On 22/03/16 11:05, BartC wrote:
On 22/03/2016 01:01, Steven D'Aprano wrote:

Pythonic code probably uses a lot of iterables:

for value in something:
     ...

in preference to Pascal code written in Python:

for index in range(len(something)):
     value = something[index]

(Suppose you need both the value and its index in the loop? Then the one-line for above won't work. For example, 'something' is [10,20,30] and you want to print:

 0: 10
 1: 20
 2: 30 )


The builtin enumerate function is the idiomatic way:

    for index, item in enumerate(something):
        ...

Regards,
Ian F
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to