Python: Counting up the elements in a list of arbitrary size in a function

Now that we’ve learned aboutrange, we have two ways of iterating through a list.

Method 1 – for item in list:

for item in list:
    print item

Method 2 – iterate through indexes:

for i in range(len(list)):
    print list[i]

Method 1 is a little easier, but can cause problems when trying to modify the list. Method 2 is much safer. Since we aren’t modifying the list, feel free to use either one on this lesson!