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

Steven Bethard steven.bethard at gmail.com
Thu Aug 31 01:56:32 CEST 2006


On 8/30/06, Raymond Hettinger <rhettinger at ewtllc.com> wrote:
> 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.

Current documentation:

zip(  	[iterable, ...])
    This function returns a list of tuples, where the i-th tuple
contains the i-th element from each of the argument sequences or
iterables. The returned list is truncated in length to the length of
the shortest argument sequence...

Proposed change:

zip(  	[iterable, ...])
    This function returns a list of tuples, where the i-th tuple
contains the i-th element from each of the argument sequences or
iterables. It is an error if the argument sequences are of different
lengths...

That seems pretty comparable in complexity to me.  Could you explain
how this makes zip() harder to understand?

Steve
-- 
I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a
tiny blip on the distant coast of sanity.
        --- Bucky Katt, Get Fuzzy


More information about the Python-3000 mailing list