.sort() problem


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

for n in start_list:

print square_list.sort()

I am getting output as None…

but i thought that i would get a sorted list i.e. either in ascending or descending order.

pls explain why is this happening?


try printing the list after sorting it



See Python: Sorting Basics, with special attention to what it says about the list.sort() method. Then consider what you have displayed here …

print square_list.sort()

The official Python web site offers lots of useful information for programmers, including documentation.


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