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
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe:
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com