Inconsistent behavior of split on empty string

B

bk_kl

Hi,

I think the following behavior of the build in function 'split' is inconsistent.
What do you think?
['']

I'm using python 2.3.3 on Windows 2000.
(Perl's split only returns all items up to the last non-empty item,
e.g. <perl>split /;/, "; ;;;"; gets you ['', ' ']. I find this confusing, too).
 
B

Bengt Richter

Hi,

I think the following behavior of the build in function 'split' is inconsistent.
What do you think?
"".split() []
"".split(";")
['']

I'm using python 2.3.3 on Windows 2000.
(Perl's split only returns all items up to the last non-empty item,
e.g. <perl>split /;/, "; ;;;"; gets you ['', ' ']. I find this confusing, too).

..split() is not an information-preserving split. It is a convenient special case
whose function should not be confused with that of .split(something).

The latter would be buggy if you could not successfully do this:
True

Unfortunately (other than making a likely bug announce itself),
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: empty separator

but otherwise I think it works.

Regards,
Bengt Richter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top