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

Guido van Rossum guido at python.org
Wed Aug 30 23:57:48 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.

[Raymond]

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

Perhaps a compromise could be to add a keyword parameter to request such an exception? (We could even add three options: truncate, pad, error, with truncate being the default, and pad being the old map() and filter() behavior.)

-- --Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-3000 mailing list