[Python-3000] have zip() raise exception for sequences of different lengths (original) (raw)

Raymond Hettinger rhettinger at ewtllc.com
Wed Aug 30 23:52:54 CEST 2006


Steven Bethard wrote:

A couple Python-3000 threads [1] [2] have indicated that the most natural use of zip() is with sequences of the same lengths. I feel the same way, and run into this all the time. Because the error would otherwise pass silently, I usually end up adding checks before each use of zip() to raise an exception if I accidentally pass in sequences of different lengths.

Any chance that zip() in Python 3000 could automatically raise an exception if the sequence lengths are different? If there's really a need for a zip that just truncates, maybe that could be moved to itertools? I think the equal-length scenario is dramatically more common, and keeping that error from passing silently would be a good thing IMHO.

-1 I think this would cause much more harm than good and wreck an otherwise easy-to-understand tool.

Raymond



More information about the Python-3000 mailing list