I have the following code:

start_list = [5, 3, 1, 2, 4]
square_list = []

for start_list in start_list: # Your code here!

square_list.append(start_list ** 2)

print square_list

**It keeps telling me that it doesn't work because I've modified start_list. Any suggestions?


you use the same name for the loop iterator as the list you are looping over, this will modify the list (overwrite the list)


I found a solution by introducing a list identical to start_list and then using the same if function structure.

Is there a way of using the code above without modifying start_list?


you could give your loop iterator a different name


Awesome, thanks for the help!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.