can't sort
Tim Heaney
heaney at cablespeed.com
Sat May 17 07:20:59 EDT 2003
Helmut Jarausch <jarausch at skynet.be> writes:
>
> Why does
>
> print [4,1,3,2].sort()
>
> just print
> None
> ?
>
> As far as I understood the docs 'sort'
> should take 'cmp' for comparisons which is
> well defined for integers.
It does the sort as you expect, but it does so in place. It does not
return the sorted list. Thus print has nothing to print.
$ python -c 'a = [4,1,3,2]; b = a.sort(); print "a =",a; print "b =",b'
a = [1, 2, 3, 4]
b = None
I hope this helps,
Tim
More information about the Python-list
mailing list