can't sort

Dan Bishop danb_83 at yahoo.com
Sat May 17 13:37:09 EDT 2003


Helmut Jarausch <jarausch at skynet.be> wrote in message news:<3ec61600$0$11142$ba620e4c at reader0.news.skynet.be>...
> Sorry for this question,
> but I am just puzzled.
> 
> Why does
> 
> print [4,1,3,2].sort()
> 
> just print
> None
> ?

Like the others have said, list.sort does an *in-place* sort.

If you want a non-in-place sort, you can do:

def sort(listToSort):
   listCopy = listToSort[:]
   listCopy.sort()
   return listCopy
print sort([4, 1, 3, 2])




More information about the Python-list mailing list