str.split() with empty separator

Hendrik van Rooyen hendrik at microcorp.co.za
Wed Sep 16 09:29:00 CEST 2009


On Tuesday 15 September 2009 14:50:11 Xavier Ho wrote:
> On Tue, Sep 15, 2009 at 10:31 PM, Ulrich Eckhardt
>
> <eckhardt at satorlaser.com>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
> > complementary.
>
> I'm not sure about asymmetry, but how would you implement a split method
> with an empty delimiter to begin with? It doesn't make much sense anyway.

I fell into this trap some time ago too.
There is no such string method.

The opposite of  "".join(aListOfChars) is
list(aString)

- Hendrik




More information about the Python-list mailing list