Beginner Question : Iterators and zip

moogyd at yahoo.co.uk moogyd at yahoo.co.uk
Sun Jul 13 09:23:40 CEST 2008


On 12 Jul, 21:50, "bruno.desthuilli... at gmail.com"
<bruno.desthuilli... at gmail.com> wrote:
> On 12 juil, 20:55, moo... at yahoo.co.uk wrote:
>
>
>
> zip is (mostly) ok. What you're missing is how to use it for any
> arbitrary number of sequences. Try this instead:
>
> >>> lists = [range(5), range(5,11), range(11, 16)]
> >>> lists
>
> [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9, 10], [11, 12, 13, 14, 15]]>>> for item in zip(*lists):
>
> ...     print item
> ...
> (0, 5, 11)
> (1, 6, 12)
> (2, 7, 13)
> (3, 8, 14)
> (4, 9, 15)

What is this *lis operation called? I am having trouble finding any
reference to it in the python docs or the book learning python.

> > Any other comments/suggestions appreciated.
>
> There's a difflib package in the standard lib. Did you give it a try ?

I'll check it out, but I am a newbie, so I am writing this as a
(useful) learning excercise.

Thanks for the help

Steven





More information about the Python-list mailing list