string, split, sort, None, huh?

Phlip phlip_cpp at my-deja.com
Fri Feb 16 17:42:58 EST 2001


Thy Pon:

Gonna split a document by linefeeds into strings, then sort the strings. 
Child's play, huh?

        lines = split ( """Mary
had
a
little
lamb""", "\n" )

        print repr(lines)
        print repr(lines.sort())

Now the output:

        ['Mary', 'had', 'a', 'little', 'lamb']
        None

So where'd that 'None' come from? The Sorting Mini-HOWTO here said strings 
are just as easy as numbers:

        http://www.python.org/doc/howto/sorting/node2.html

Variations with 'cmp' and 'lambda x, y: cmp(x, y)' also get 'None'.

-- 
  Phlip                          phlip_cpp at my-deja.com
============ http://c2.com/cgi/wiki?PhlIp ============
  --  Proud victim of the dreaded boomerang effect  --





More information about the Python-list mailing list