Python – Error: list index out of range

I’ve been developing in Python for just over two years since 2014, so I’m still a newbie, and I hit this error recently: “Error: list index out of range”

It took a little bit longer than perhaps it should have done to figure out what I’d done wrong.

The code was something like this pseudo-function, which counts the number of even numbers passed in a list:

def count_evens(nums):
count = 0
for i in nums:
if nums[i] % 2 == 0:
count += 1
return count