"Steve Holden" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
<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


-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to