def same_values(lst1, lst2):
new_lst = []
for index in range(len(lst1)):
if lst1[index] == lst2[index]:
new_lst.append(index)
return new_lst
the instructions say to loop through the two lists so how come it looks like this code only loops through lst1
and does not have a for
line written for lst2
?
originally i had written:
def same_values(lst1, lst2):
new_list = []
for num in range(len(lst1)):
for num in range(len(lst2)):
if lst1[num] == lst2[num]:
new_list.append(num)
return new_list
this is from project 4 on this page: https://www.codecademy.com/courses/learn-python-3/articles/advanced-python-code-challenges-loops