Why do we only need the range for one list?

#Write your function here
def same_values(lst1,lst2):
  lst3 = []
  for index in range(len(lst1)):
    if lst1[index] == lst2[index]:
      lst3.append(index)
  return lst3
  

#Uncomment the line below when your function is done
print(same_values([5, 1, -10, 3, 3], [5, 10, -10, 3, 5]))

Ok so Im quite confused here. Why do we only have to say “for index in range(len(lst1))”. How come we are not also looking at the range for the second list. Can someone explain to me what the loop is actually doing?

1 Like

given the lists are of the same length, the indices for both lists are the same. Range just produces a list, this list just contains integers. These integers just so happen to match the indexes we need, so we can use these integers from the range list, to lookup values by index in both lst1 and lst2

3 Likes