Re: a dictionary from a list

2005-06-27 Thread Raymond Hettinger
[Roy Smith] > I also think the published description is needlessly confusing. Why does > it use > >{'one': 2, 'two': 3} > > as the example mapping when > >{'one': 1, 'two': 2} > > would illustrate exactly the same point but be easier to comprehend. The > mapping given is the kind of thing

Re: a dictionary from a list

2005-06-27 Thread Raymond Hettinger
[Roy Smith] > I also think the published description is needlessly confusing. Why does > it use > >{'one': 2, 'two': 3} > > as the example mapping when > >{'one': 1, 'two': 2} > > would illustrate exactly the same point but be easier to comprehend. The > mapping given is the kind of thing

Re: a dictionary from a list

2005-06-25 Thread George Sakkis
"Steven D'Aprano" wrote: > On Sat, 25 Jun 2005 06:44:22 -0700, George Sakkis wrote: > > > "Roy Smith" <[EMAIL PROTECTED]> wrote: > > > >> I just re-read the documentation on the dict() constructor. Why does it > >> support keyword arguments? > >> > >>dict(foo="bar", baz="blah") ==> {"foo":"ba

Re: a dictionary from a list

2005-06-25 Thread Steven D'Aprano
On Sat, 25 Jun 2005 06:44:22 -0700, George Sakkis wrote: > "Roy Smith" <[EMAIL PROTECTED]> wrote: > >> I just re-read the documentation on the dict() constructor. Why does it >> support keyword arguments? >> >>dict(foo="bar", baz="blah") ==> {"foo":"bar", "baz"="blah"} >> >> This smacks of c

Re: a dictionary from a list

2005-06-25 Thread Scott David Daniels
Roy Smith wrote: > Terry Hancock <[EMAIL PROTECTED]> wrote: > ... > I just re-read the documentation on the dict() constructor. Why does it > support keyword arguments? > >dict(foo="bar", baz="blah") ==> {"foo":"bar", "baz"="blah"} > > This smacks of creeping featurism. Is this actually us

Re: a dictionary from a list

2005-06-25 Thread Michael Hoffman
Roy Smith wrote: > I just re-read the documentation on the dict() constructor. Why does it > support keyword arguments? > >dict(foo="bar", baz="blah") ==> {"foo":"bar", "baz"="blah"} > > This smacks of creeping featurism. Is this actually useful in real code? Personally, I use it all t

Re: a dictionary from a list

2005-06-25 Thread Jp Calderone
On Sat, 25 Jun 2005 09:10:33 -0400, Roy Smith <[EMAIL PROTECTED]> wrote: >Terry Hancock <[EMAIL PROTECTED]> wrote: >> Before the dict constructor, you needed to do this: >> >> d={} >> for key in alist: >> d[key]=None > >I just re-read the documentation on the dict() constructor. Why does it >s

Re: a dictionary from a list

2005-06-25 Thread George Sakkis
"Roy Smith" <[EMAIL PROTECTED]> wrote: > I just re-read the documentation on the dict() constructor. Why does it > support keyword arguments? > >dict(foo="bar", baz="blah") ==> {"foo":"bar", "baz"="blah"} > > This smacks of creeping featurism. Is this actually useful in real code? > It took

Re: a dictionary from a list

2005-06-25 Thread Roy Smith
Terry Hancock <[EMAIL PROTECTED]> wrote: > Before the dict constructor, you needed to do this: > > d={} > for key in alist: > d[key]=None I just re-read the documentation on the dict() constructor. Why does it support keyword arguments? dict(foo="bar", baz="blah") ==> {"foo":"bar", "baz

Re: a dictionary from a list

2005-06-25 Thread Terry Hancock
On Friday 24 June 2005 05:26 pm, infidel wrote: > dict((x, None) for x in alist) or if you want it to run in 2.3 (before "generator expressions"): dict( [(x,None) for x in alist] ) Before the dict constructor, you needed to do this: d={} for key in alist: d[key]=None which is still only 3

Re: a dictionary from a list

2005-06-24 Thread Peter Hansen
Dave Cook wrote: > On 2005-06-24, infidel <[EMAIL PROTECTED]> wrote: > > >>dict((x, None) for x in alist) > > Whoa, I thought dictionary comprehensions were still planned feature. I > guess I gotta start paying closer attention. Added in Python 2.4, it's actually a generator expression as the

Re: a dictionary from a list

2005-06-24 Thread Dave Cook
On 2005-06-24, infidel <[EMAIL PROTECTED]> wrote: > dict((x, None) for x in alist) Whoa, I thought dictionary comprehensions were still planned feature. I guess I gotta start paying closer attention. Dave Cook -- http://mail.python.org/mailman/listinfo/python-list

Re: a dictionary from a list

2005-06-24 Thread George Sakkis
"Rocco Moretti" wrote: > Are you sure you need a dictionary? You may want to look at the Set > module instead, if the values aren't important. Set is the name of the type in the module sets, introduced in 2.3. Since 2.4 you can use the builtin set type. Here's the import snippet that works for 2.

Re: a dictionary from a list

2005-06-24 Thread Rocco Moretti
David Bear wrote: > I know there must be a better way to phrase this so google understands, but > I don't know how.. So I'll ask people. > > Assume I have a list object called 'alist'. > > Is there an easy way to create a dictionary object with the members of > 'alist' being the keys in the dicti

Re: a dictionary from a list

2005-06-24 Thread Leif K-Brooks
David Bear wrote: > Is there an easy way to create a dictionary object with the members of > 'alist' being the keys in the dictionary, and the value of the keys set to > null? adict = dict.fromkeys(alist) -- http://mail.python.org/mailman/listinfo/python-list

Re: a dictionary from a list

2005-06-24 Thread infidel
dict((x, None) for x in alist) -- http://mail.python.org/mailman/listinfo/python-list

Re: a dictionary from a list

2005-06-24 Thread Benji York
David Bear wrote: > Assume I have a list object called 'alist'. > > Is there an easy way to create a dictionary object with the members of > 'alist' being the keys in the dictionary, and the value of the keys set to > null? You mean None, right? :) >>> a_list = [1, 2, 3, 'a', 'b', 'c'] >>> di