Bug or feature? 'abc'.split('') rejects empty separator
Bengt Richter
bokr at oz.net
Sun Feb 10 14:25:18 EST 2002
>>> 'abc'.startswith('')
1
>>> 'abc'.endswith('')
1
>>> 'abc'.find('')
0
>>> 'abc'.rfind('')
3
>>> 'abc'.find('',1)
1
AND:
>>> z=list('abc')
>>> z
['a', 'b', 'c']
>>> ''.join(z)
'abc'
BUT:
>>> 'abc'.split('')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: empty separator
Wouldn't it make sense to return list('abc') ?
or, ugly, but consistent with *find results
(finding the separator front, back, and between all):
>>> ';a;b;c;'.split(';')
['', 'a', 'b', 'c', '']
Regards,
Bengt Richter
More information about the Python-list
mailing list