a query on sorting
Paul Rubin
http
Wed Sep 27 23:40:20 EDT 2006
Gabriel Genellina <gagsl-py at yahoo.com.ar> 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 items.
>
> sorted([(a[i],i) for i in range(len(a))])
I think
sorted((x,i) for i,x in enumerate(a))
looks nicer than the above.
More information about the Python-list
mailing list