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', '')]




Edit: I see they addressed this in 3.5 (maybe earlier), with an option:

"itertools.zip_longest(*iterables, fillvalue=None)

Make an iterator that aggregates elements from each of the iterables. If the iterables are of uneven length, missing values are filled-in with fillvalue. Iteration continues until the longest iterable is exhausted."

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to