More for "for"


#1

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

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

print square_list

why is this not working? what's meant by "return is out of function', a message given by the interpretor?


#2

Return has to be used in a function, you cant use return in a for loop (well, you could if the for loop was in a function). You need a different approach, with the return keyword


#3

Return is ONLY inside functions NOT for loops. Hope that helps!


#4

thanks to both of you kind people!


#5

A post was split to a new topic: More for "for", need help