str.split() with empty separator
vlastimil.brom at gmail.com
Tue Sep 15 15:33:51 CEST 2009
2009/9/15 Ulrich Eckhardt <eckhardt at satorlaser.com>:
> "'abc'.split('')" gives me a "ValueError: empty separator".
> However, "''.join(['a', 'b', 'c'])" gives me "'abc'".
> Why this asymmetry? I was under the impression that the two would be
maybe it isn't quite obvious, what the behaviour in this case should be;
re.split also works with empty delimiter (and returns the original string)
>>> re.split("", "abcde")
If you need to split the string into the list of single characters
like in your example, list() is the possible way:
['a', 'b', 'c', 'd', 'e']
More information about the Python-list