Code Point
September 10, 2010, 06:45:56 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Geshi Sintax Hilighting Mod Installed. Tens of languages available.
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: list.sort() is emptying my list  (Read 2607 times)
Dalton
Jr. Member
*

Karma: 0
Offline Offline

Posts: 3


« on: September 12, 2006, 02:20:16 PM »

The sort() method of the list is not working. Instead it is emptying my list:

Code
>>> l = ['e', 'c', 'a']
>>> l = l.sort()
>>> print l
None

What is the problem?
Logged
Telplate
Jr. Member
*

Karma: 1
Offline Offline

Posts: 4


« Reply #1 on: September 12, 2006, 02:25:59 PM »

The sort() method sorts the list in place and returns None. That is, if you assign a variable to the result of the sort() method the variable will refer to None.

Try it like this:

Code
>>> l = ['e', 'c', 'a']
>>> l.sort()
>>> print l
['a', 'c', 'e']
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!