Bug or feature? 'abc'.split('') rejects empty separator

Erik Max Francis max at alcyone.com
Sun Feb 10 18:36:20 EST 2002


Neil Schemenauer wrote:

> Bengt Richter wrote:
>
> > Wouldn't it make sense to return list('abc') ?
> 
> It would also make sense to return ['a', 'b', 'c'].  Since it's not
> obvious what you want Python raises an error.

That's what list('abc') would return.  But in actuality, for it to be
consistent with the rest of string.split's behavior, 'abc'.split('')
would have to return ['', 'a', 'b', 'c', ''], not ['a', 'b', 'c'].

Another beautiful example of why string.split('') should raise an error
instead of trying to guess what you mean.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ Laws are silent in time of war.
\__/ Cicero
    Esperanto reference / http://www.alcyone.com/max/lang/esperanto/
 An Esperanto reference for English speakers.



More information about the Python-list mailing list