More with 'for'


I thought my code was producing the desired result...all numbers in start_list squared then sorted. I think I'm not understanding what the instructions are asking of me. Any help would be appreciated.

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

for start_list in start_list:

print square_list


Since, we're trying to square each number in our list and append it to square_list, we need to create a variable that will be used to iterate through start_list in our for loop.


I think I'm fundamentally misunderstanding something...
The result of my code (above) produces the result: [1, 4, 9, 16, 25]

Your response:

Maybe I'm just having one of those days, but isn't that what my code did?


Yes, that's your result. It is the correct result.

Yes. I mean it's only like this when appending to non-lists.
(my apologies... in your code, it looked like you were appending to start_list, so that's why I said that. So ignore that.)

We are asked to not modify start_list, so we need to create a new variable that will iterate through start_list. :slight_smile: Do you know what I mean?


I’m having the same issue - correct result but telling me to not modify start_list and I can’t figure out the solution


Hello @bunn_cole. Check out this link:

If, you need more help, or if this doesn’t solve your problem, you can create a new topic like it’s advised in the Guidelines. Thanks :slight_smile:


Perhaps you misunderstood my note - I am having the same problem and am looking for a solution.


Do you mean by me giving you the full answer? I’m sorry, but that’s against the guidelines, so I can’t do that. Besides, you don’t really learn anything by just copy and pasting.


please don’t modify start_list use another variable like A which is provided in hint:

start_list = [5, 3, 1, 2, 4]
square_list = []
for A in start_list:
print square_list


Thank you for giving a straight answer, i’ve been on this same lesson for 2 hours :tired_face:.
To my understanding the syntax for the for loop is :
“for <some_variable> in <some_list>:”

Is this the general idea of it?


Guidelines? What are these Guidelines??? I might in some trouble…:expressionless:


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