a query on sorting
Paul McGuire
ptmcg at austin.rr._bogus_.com
Wed Sep 27 09:01:29 EDT 2006
"Steve Holden" <steve at holdenweb.com> wrote in message
news:mailman.796.1159357863.10491.python-list at python.org...
<snip>
>>> [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 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 create the list of tuples, I have to call the tuple
constructor on each one, as in:
map(tuple,map(reversed,list(enumerate(a))))
However, sorted returns a list, not a listsortediterator. Why the
difference in these two builtins?
I guess you can beat a dead horse into the ground, but you can't make him
drink.
-- Paul
More information about the Python-list
mailing list