Problem


#1

Hi,

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)

square_list.sort()
print square_list

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


Problem
Problem
#2

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


#3

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?


#4

you could give your loop iterator a different name


#5

Awesome, thanks for the help!


#6

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