A Faster Way...

Fredrik Lundh fredrik at pythonware.com
Wed May 11 11:55:28 EDT 2005


"stasz" wrote:

> > hmm, there's lots of ways, huh?  you can use itertools.zip instead of
> > builtin zip, or do:
> >
> >  map(None, list1, list2)
>
> Not!

huh?

> One should try a possible solution first,
> >>> l1 = range(10)
> >>> l2 = range(10,20)
> >>> l1
> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
> >>> l2
> [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
> >>> map(None,l1,l2)
> [(0, 10), (1, 11), (2, 12), (3, 13), (4, 14), (5, 15), (6, 16), (7, 17), (8, 18), (9, 19)]

and that's different from zip in exactly what way?

>>> zip(l1,l2)
[(0, 10), (1, 11), (2, 12), (3, 13), (4, 14), (5, 15), (6, 16), (7, 17), (8, 18), (9, 19)]

(as Gene pointed out, the only difference between map(None, ...) and
zip(...) is that map() pads the shorter sequence, while zip() truncates
the long sequence).

</F>






More information about the Python-list mailing list