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

Barry Warsaw barry at python.org
Thu Aug 31 00:21:34 CEST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Aug 30, 2006, at 5:57 PM, Guido van Rossum wrote:

> 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.)

Caveat: I don't even know if /I/ like this, but I'll spit it out  
anyway in case it spurs an actual good idea from someone else. :)

What about a keyword argument called 'filler' which can be an n-sized  
sequence or a callable.  If it's a sequence, then when zip arguments  
are exhausted, you pull values for that item from the appropriate  
element of the sequence.  If it's a callable, you call it with the  
items you have and None's for the exhausted ones.  Whatever filler()  
returns, zip returns.  filler() could then splice in whatever values  
it wants.  Yeah 'None' for the missing ones can be ambiguous but oh  
well.

You raise a ValueError if filler is a sequence of size that doesn't  
match the number of zip arguments or if filler() doesn't return an  
appropriately sized sequence.

yeah-okay-dumb-5-minute-idea-ly y'rs,
- -Barry

P.S. OTOH, zip's current semantics never bothered me much in practice.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Darwin)

iQCVAwUBRPYPc3EjvBPtnXfVAQL5RQQAh93Sr84HaLP0Zo4hr3JBuWkhipryIx+A
eCnGKXxXa8fTvBuRcaHFAryPnXxrnrhs1pmpQsf3/scJTHcwXstX8OMJvHrFRqcV
KHF8qRazP271RnbDQuDBTJwcwsTFpjHtDVyNbApYxQDreiy77q4ZDyuraICKlkqo
rT8hfF3Mab8=
=+9HZ
-----END PGP SIGNATURE-----


More information about the Python-3000 mailing list