Sorting a list

J Sisson sisson.j at gmail.com
Tue Oct 28 10:07:50 EDT 2008


To expand on Tino's response, sort() sorts in place and does not *return* a
sorted copy of the list.

In other words:

unsortedList = list(["XYZ","ABC"])
unsortedList.sort()
print sortedList

is correct.  Since sort() returns None, you lose your list if you do:

unsortedList = unsortedList.sort()

Jonathon
On Tue, Oct 28, 2008 at 8:59 AM, Tino Wildenhain <tino at wildenhain.de> wrote:

> RC wrote:
>
>> unsortedList = list(["XYZ","ABC"])
>>
>> sortedList = unsortedList.sort()
>> print sortedList
>>
>>
>> Why this return None?
>>
>
> Because you did not read the documentation.
>
> Regards
> Tino
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


-- 
Computers are like air conditioners...
They quit working when you open Windows.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20081028/c28b7302/attachment-0001.html>


More information about the Python-list mailing list