Re: a query on sorting

2006-10-01 Thread Fredrik Lundh
Scott David Daniels wrote: >> map(tuple,map(reversed,list(enumerate(a > > Doesn't the following read more easily? > > [tuple(reversed(x)) for x in enumerate(a)] that involves two extra name lookups for each item in the sequence, though, so it doesn't execute more easily. -- http:/

Re: a query on sorting

2006-10-01 Thread Scott David Daniels
Paul McGuire wrote: > In the interests of beating a dead horse into the ground >(metaphor-mixing?), > I looked at using map to one-line the OP's request, and found an interesting > inconsistency. > > I tried using map(reversed, list(enumerate(a))), but got back a list of > iterators. To c

Re: a query on sorting

2006-09-28 Thread Steve Holden
Paul Rubin wrote: > Gabriel Genellina <[EMAIL PROTECTED]> writes: > >>> >>> sorted((x[1], x[0]) for x in enumerate(a)) >>>[(1, 7), (2, 4), (2, 8), (3, 2), (4, 1), (5, 3), (6, 5), (7, 6), (9, 0)] >> >>Why forcing to use enumerate if it doesn't fit? And a generator won't >>help here since you have

Re: a query on sorting

2006-09-28 Thread Steve Holden
Paul McGuire wrote: > "Steve Holden" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > > >>> [x for x in enumerate(a)] > [(0, 9), (1, 4), (2, 3), (3, 5), (4, 2), (5, 6), (6, 7), (7, 1), (8, 2)] > > > Just curious, Steve, but why do this list comprehension when: > > list(enum

Re: a query on sorting

2006-09-27 Thread Paul Rubin
Gabriel Genellina <[EMAIL PROTECTED]> writes: > > >>> sorted((x[1], x[0]) for x in enumerate(a)) > >[(1, 7), (2, 4), (2, 8), (3, 2), (4, 1), (5, 3), (6, 5), (7, 6), (9, 0)] > > Why forcing to use enumerate if it doesn't fit? And a generator won't > help here since you have to access all the item

Re: a query on sorting

2006-09-27 Thread Gabriel Genellina
At Wednesday 27/9/2006 08:51, Steve Holden wrote: If you want the indexes as well you need to become a bit tricky. Remember that enumerate() will produced two-element tuples with the index value associated with the list value. >>> [x for x in enumerate(a)] [(0, 9), (1, 4), (2, 3), (3, 5), (4,

Re: a query on sorting

2006-09-27 Thread Paul McGuire
"Steve Holden" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >>> [x for x in enumerate(a)] [(0, 9), (1, 4), (2, 3), (3, 5), (4, 2), (5, 6), (6, 7), (7, 1), (8, 2)] Just curious, Steve, but why do this list comprehension when: list(enumerate(a)) works just as well? In the in

Re: a query on sorting

2006-09-27 Thread Steve Holden
Satya Upadhya wrote: > Dear Friends, > I am having a few issues with respect to sorting using python. I am using > Python 2.4.3 Win32 (IDLE 1.1.3). > x = [2,6,4] x.sort() x > [2, 4, 6] x = [2,6,4] y = [] y = x.sort() y print y > None > > So the problem esse