[Python-3000] have zip() raise exception for sequences of different lengths
Georg Brandl
g.brandl at gmx.net
Tue Sep 5 19:03:32 CEST 2006
Giovanni Bajo wrote:
> 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()
> ...
enumerate() starts at 0, count(1) at 1, so you'd have to do a
lineno += 1
in the body too.
Whether
for lineno, ts, line in zip(count(1), timestamp(), sys.stdin):
is more complicated than
for lineno, line in enumerate(sys.stdin):
ts = time.time()
lineno += 1
is a stylistic question.
(However, enumerate() could grow a second argument specifying the
starting index).
Georg
More information about the Python-3000
mailing list