[Tutor] packing a list of lists

Kent Johnson kent37 at tds.net
Fri Aug 28 19:57:57 CEST 2009


On Fri, Aug 28, 2009 at 11:20 AM, vince spicer<vinces1979 at gmail.com> wrote:

> Or even cleaner with list comprehension
>
> def pack(foo):
>     return [x for x in enumerate(foo, 1)]

Or just list(enumerate(foo, 1))

For Python 2.5 use
[ [i+1, x] for i, x in enumerate(foo) ]

Kent


More information about the Tutor mailing list