Why do I get an IndexError (or TypeError, or just wrong results) from “ar[i]” inside “for i in ar”?
When looping over a list, the for variable (in this example i) represents the current element of the list. For example, given ar = [1, 5, 10], i will have the successive values 1, 5 and 10 each time through the loop. Since the length of the list is 3, the maximum permitted index is … Read more