Is there a reason zip() wipes out data?

Dan Sommers dan at tombstonezero.net
Mon May 9 00:29:54 EDT 2016


On Mon, 09 May 2016 00:22:46 -0400, DFS wrote:

> python 2.7.11 docs: "The returned list is truncated in length to the 
> length of the shortest argument sequence."
> 
> 
> a = ['who','let','the']
> b = ['dogs','out?']
> c = zip(a,b)
> 
> print c
> [('who', 'dogs'), ('let', 'out?')]
> 
> 
> Wouldn't it be better to return an empty element than silently kill your 
> data?
> 
> [('who', 'dogs'), ('let', 'out?'), ('the', '')]

>>> dfs_zip([1, 2, 3], [4, 5])
[(1, 4), (2, 5), (3, '')]

No, that's not much better, thanks.

In the face of ambiguity, refuse the temptation to guess.



More information about the Python-list mailing list