Will McGugan wrote:
Hi,

I'm curious about the behaviour of the str.split() when applied to empty strings.

"".split() returns an empty list, however..

"".split("*") returns a list containing one empty string.

Both of these make sense as limiting cases.

Consider

>>> "a b c".split()
['a', 'b', 'c']
>>> "a b".split()
['a', 'b']
>>> "a".split()
['a']
>>> "".split()
[]

and

>>> "**".split("*")
['', '', '']
>>> "*".split("*")
['', '']
>>> "".split("*")
['']

The split() method is really doing two somewhat different things
depending on whether it is given an argument, and the end-cases
come out differently.

--
Greg Ewing, Computer Science Dept,
University of Canterbury,       
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to