Sorting a list
Brian Blais
bblais at bryant.edu
Tue Oct 28 09:57:20 EDT 2008
On Oct 28, 2008, at 9:45 , RC wrote:
> unsortedList = list(["XYZ","ABC"])
>
> sortedList = unsortedList.sort()
> print sortedList
>
the sort method is in-place, so it modifies the object which calls
it, and doesn't return anything:
In [1]:unsortedList = list(["XYZ","ABC"])
In [2]:sortedList = unsortedList.sort()
In [3]:print sortedList
None
In [4]:print unsortedList
['ABC', 'XYZ']
or, better, just:
In [5]:unsortedList = list(["XYZ","ABC"])
In [6]:unsortedList.sort()
In [7]:print unsortedList
['ABC', 'XYZ']
bb
--
Brian Blais
bblais at bryant.edu
http://web.bryant.edu/~bblais
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20081028/fd1542fb/attachment-0001.html>
More information about the Python-list
mailing list