please help shrink this each_with_index() implementation

Nobody nobody at nowhere.com
Wed Jan 6 12:59:40 EST 2010


On Tue, 05 Jan 2010 12:20:58 -0800, Marco Nawijn wrote:

> You could use the build-in function enumerate inside a list
> comprehension.
> 
>>>> seq = range(5)
>>>> [ (i,s) for i,s in enumerate(seq) ]
> [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4)]

Just use list(), i.e. "list(enumerate(seq))".




More information about the Python-list mailing list