.sort() problem


#1

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

for n in start_list:
square_list.append(n**2)

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?


#2

try printing the list after sorting it


#3

@adi244,

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.


#4

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