[Python-3000] have zip() raise exception for sequences of different lengths (original) (raw)
Raymond Hettinger rhettinger at ewtllc.com
Thu Aug 31 00:41:08 CEST 2006
- Previous message: [Python-3000] have zip() raise exception for sequences of different lengths
- Next message: [Python-3000] have zip() raise exception for sequences of different lengths
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.)
FWIW, I intend to add an itertool called izip_longest() which allows a
pad value to be specified. In deciding to accept that feature request,
I put a great deal of thought and research into the idea. Along the
way, I looked at other languages and found both truncating and padding
versions of zip but did not find any version that raised an exception.
IMO, such a provision would foul the waters and complicate the use of an
otherwise simple function.
Until now, there have been zero requests for zip() to have exception raising behavior.
For Python 3k, I recommend:
- simply replacing zip() with itertools.izip()
- keeping the zip_longest() in a separate module
- punting on an exception raising version
The first covers 99% of use cases. The second covers a handful of situations that are otherwise difficult to deal with. The third is a YAGNI.
Raymond
- Previous message: [Python-3000] have zip() raise exception for sequences of different lengths
- Next message: [Python-3000] have zip() raise exception for sequences of different lengths
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]