Re: Help with creating a dict from list and range

2005-10-16 Thread Fredrik Lundh
Steve Holden wrote: > Question: what's the difference between > > dict((name, seq) for seq, name in enumerate(description)) > > (the improved version of my answer posted by Scott David Daniels) and > > dict(enumerate(description)) a missing def enumerate(x, enumerate=enumerate): # ov

Re: Help with creating a dict from list and range

2005-10-16 Thread Steve Holden
George Sakkis wrote: > "James Stroud" <[EMAIL PROTECTED]> wrote: >>Could be even simpler since enumerate creates tuples anyway: >> >>dct = dict(x for x in enumerate(description)) >> >>James >> >>On Friday 14 October 2005 08:37, Steve Holden wrote: >> >>> >>> dct = dict((x[1], x[0]) for x in enume

Re: Help with creating a dict from list and range

2005-10-15 Thread Scott David Daniels
James Stroud wrote: > On Friday 14 October 2005 08:37, Steve Holden wrote: >> >>> dct = dict((x[1], x[0]) for x in enumerate(description)) To make the code a breath more obvious: >>> dct = dict((name, seq) for seq, name in enumerate(description)) has the same results. >> >>> dct >> >>{'second': 1

Re: Help with creating a dict from list and range

2005-10-14 Thread George Sakkis
"James Stroud" <[EMAIL PROTECTED]> wrote: > Could be even simpler since enumerate creates tuples anyway: > > dct = dict(x for x in enumerate(description)) > > James > > On Friday 14 October 2005 08:37, Steve Holden wrote: > > >>> dct = dict((x[1], x[0]) for x in enumerate(description)) > > >>> d

Re: Help with creating a dict from list and range

2005-10-14 Thread James Stroud
Could be even simpler since enumerate creates tuples anyway: dct = dict(x for x in enumerate(description)) James On Friday 14 October 2005 08:37, Steve Holden wrote: > >>> dct = dict((x[1], x[0]) for x in enumerate(description)) > >>> dct > > {'second': 1, 'third': 2, 'first': 0} > > regards >

Re: Help with creating a dict from list and range

2005-10-14 Thread Steve Holden
Echo wrote: > Hello, > Here is what I am trying to do. I am trying to make a dict that has a > key that is the value an element in a list and the value for the dict to > be the index. > This is the closest I have been able to get: > dict((d[0],i) for d in self.cu.description for i in > xrange(l