9. More with 'for' | Wrong sorting


#1




My code sorts the numbers wrong and I don't know why/how. Error message says "Oops, try again. It looks like square_list has 25 at index 3 instead of 16"


I expected it all to work but couln't figure it out. Please Help!


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

# Your code here!
for x in start_list:
    square_list.sort()
    square_list.append(x**2)

print square_list


#2

you sort before appending to list, you should sort after appending

if you want to do it even better, sort after the for loop so that sorting only happens once rather then each iteration


#3

Ok, thank you, really helped me understanding everything much better


#4