[Tutor] packing a list of lists
vince spicer
vinces1979 at gmail.com
Fri Aug 28 18:57:33 CEST 2009
On Fri, Aug 28, 2009 at 10:49 AM, kevin parks <kp8 at me.com> wrote:
>
> Thanks for the replies. Though the list comprehension does not work:
>
> TypeError: enumerate() takes exactly 1 argument (2 given)
>
>
> On Aug 29, 2009, at 12:20 AM, vince spicer wrote:
>
>
>>
>> #print foohough I didn't test your code, I think what you are trying
>> to accomplish can be done using enumerate cleaner
>>
>>
>> def pack(foo):
>> out = []
>> for x,y in enumerate(foo, 1):
>> out.append((x,y))
>> return out
>>
>>
>>
>>
>> Or even cleaner with list comprehension
>>
>> def pack(foo):
>> return [x for x in enumerate(foo, 1)]
>>
>>
>>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
What version of python are using, python 2.6+ have a "start" parameter
http://docs.python.org/library/functions.html#enumerate
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090828/46922950/attachment.htm>
More information about the Tutor
mailing list