Reverse zip() ?

Casey McGinty casey.mcginty at gmail.com
Wed Dec 3 22:48:10 CET 2008


> The corner case is when dealing with empty lists and there aren't
> enough items to unpack.
>
>
Another solution to zip(), with a slightly different behaviour for conner
cases ....

>>> a = (1,2,3)
>>> b = (1,2,3)
>>> c = (1,2,3,4)
>>> zip(a,b)
[(1, 1), (2, 2), (3, 3)]
>>> map(None,a,b)
[(1, 1), (2, 2), (3, 3)]
>>> zip(a,c)
[(1, 1), (2, 2), (3, 3)]
>>> map(None,a,c)
[(1, 1), (2, 2), (3, 3), (None, 4)]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20081203/37eb25fc/attachment.html>


More information about the Python-list mailing list