M&C2: Assuming that all list elements must be accessed

Students often see code segments that iterate through a list and perform some task on every element in the list. This can lead to some misunderstanding when writing code that does not need to access all elements. The following video addresses the misconception.

Example Code

myData = [1, 1, 1, 1, 1, 1]
i = 0
while i < len(myData) :
    if i % 2 == 0 :
    myData[i] = myData[i] + 1
    i = i + 1

Video Length: 2:02