[Python-3000] have zip() raise exception for sequences of different lengths
Giovanni Bajo
rasky at develer.com
Tue Sep 5 15:17:49 CEST 2006
Raymond Hettinger wrote:
> It's a PITA because it precludes all of the use cases whether the
> inputs ARE intentionally of different length (like when one argument
> supplys an infinite iterator):
>
> for lineno, ts, line in zip(count(1), timestamp(), sys.stdin):
> print 'Line %d, Time %s: %s)' % (lineno, ts, line)
which is a much more complicated way of writing:
for lineno, line in enumerate(sys.stdin):
ts = time.time()
...
[assuming your "timestamp()" is what I think it is, never heard of it
before].
I double-checked my own uses of zip() and they seem to follow the trend of
those in Python stdlib: most of the cases are really programming errors if
the two sequences do not match in length. I reckon the usage of infinite
iterators is generally much less common.
--
Giovanni Bajo
More information about the Python-3000
mailing list