Stuck on the indentation placement of the final return statement in question #4 of Python Code Challenges: Loops (Advanced). See link below …
https://www.codecademy.com/courses/learn-python-3/articles/advanced-python-code-challenges-loops
I visually see the difference in output between my incorrect code solution and the correct Codecademy code solution. But I am failing to process in my head why the outputs are this way. This is my incorrect code solution where line 2 and the last line are indented the same amount (see below). Note that this indentation placement is the same as the placement of the correct code solutions in Questions #2 and Questions #3! …
def same_values(lst1, lst2):
–>new_list = #MATCHING INDENT
–>for index in range(len(lst1)):
---->for index in range(len(lst2)):
------>if lst1[index] == lst2[index]:
-------->new_list.append(index)
–>return new_list #MATCHING INDENT
… compared to the output of the correct code solution where it’s line 4 and the last line that have matching indentation levels …
def same_values(lst1, lst2):
–>new_list =
–>for index in range(len(lst1)):
---->for index in range(len(lst2)): #MATCHING INDENT
------>if lst1[index] == lst2[index]:
-------->new_list.append(index)
---->return new_list #MATCHING INDENT
Befuddled here with global/local placement again … (sigh)