str.split() with empty separator
davea at ieee.org
Tue Sep 15 15:35:58 CEST 2009
Ulrich Eckhardt wrote:
> "'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
I think the problem is that join() is lossy; if you try "".join(['a',
'bcd', 'e']) then there's no way to reconstruct the original list with
split(). Now that can be true even with actual separators, but perhaps
this was the reasoning.
Anyway, if you want to turn a string into a list of single-character
strings, then use
More information about the Python-list