What's the cleanest code that iterates on the lines of a text file, while simultaniously increamenting a counter?
I understand that with multiple assignment, there's a cleaner syntax than
i = 0
for line in f:
...
++i
for i, line in enumerate(f):
print i, line
As seen here: http://docs.python.org/library/functions.html#enumerate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With