3 ms·
It would also be more idiomatic to write for i, line in enumerate(sys.stdin): print '{:>6} {}'.format(i, line[:-1])
by jdnier 13y ago
It would also be more idiomatic to write
for i, line in enumerate(sys.stdin):
print '{:>6} {}'.format(i, line[:-1])
- riskable 13y agoUnless you want your line numbers to start at 0, do this instead: import sys for lineno, line in enumerate(sys.stdin, 1): print('{:>6} {}'.format(lineno, line[:-1])) The second argument to enumerate() is the 'start' (can also be a keyword). So by passing a 1 we start there instead of 0.