More with 'for'


-I thought I had everything right, but I keep get the error message on line 6, with the code: square_list.sort()
AttributeError: 'NoneType' object has no attribute 'sort'

Thanks for the help!

Error message:
Traceback (most recent call last):
File "python", line 7, in
AttributeError: 'NoneType' object has no attribute 'sort'

1. start_list =  [5,3,1,2,4]
2. square_list =[ ]
3.# Your code here!
4. for number in start_list:
5.     square_list= start_list.append(number**2)
6.     square_list.sort()
7. print square_list


append will update the list for you, no need to also store it in a variable

are you certain you want to sort the list each iteration of the loop, not just at the end?


I want to loop at the end, and I thought that how the code should look like. I'm sorry but I thought my original code square_list.sort() will sort the list at the end, not each iteration.

I'm curious; after I created the square_list and want to make change to the list item by dividing every item in the square_list by 2.

here is my code:

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

for number in start_list:

print square_list

But the console produce error message. Below is the link to my code:

Thanks very much for your help.


you appending to the list you are looping over, this causes an infinity loop

please just do what the exercise tell you, otherwise go play in the codecademy labs


Hey mate,

I just finished the exercise and I think that you just have to pay attention to line four and how this relates to line 5. As stetim94 said 'append will update the list for you, no need to also store it in a variable'


Your do not need to use start_list inside the for loop..square_list (number**2) will suffice and thats what the question demands..also sort must be outside the for loop before print.


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