[Python-ideas] str.split with empty separator
Alexandre Conrad
alexandre.conrad at gmail.com
Thu Jul 29 12:41:35 CEST 2010
Hello all,
What if str.split could take an empty separator?
>>> 'banana'.split('')
['b', 'a', 'n', 'a', 'n', 'a']
I know this can be done with:
>>> list('banana')
['b', 'a', 'n', 'a', 'n', 'a']
I think that, semantically speaking, it would make sens to split where
there are no characters (in between them). Right now you can join from
an empty string:
''.join(['b', 'a', 'n', 'a', 'n', 'a'])
So why can't we split from an empty string?
This wouldn't introduce any backwards incompatible changes as
str.split currently can't have an empty separator:
>>> 'banana'.split('')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: empty separator
I would love to see my banana actually split. :)
Regards,
--
Alex
twitter.com/alexconrad
More information about the Python-ideas
mailing list