split() and string.whitespace

MRAB google at mrabarnett.plus.com
Tue Nov 4 18:49:45 EST 2008


On Nov 4, 8:00 pm, bearophileH... at lycos.com wrote:
> MRAB:
>
> > It's interesting, if you think about it, that here we have someone who
> > wants to split on a set of characters but 'split' splits on a string,
> > and others sometimes want to strip off a string but 'strip' strips on
> > a set of characters (passed as a string).
>
> That can be seen as a little inconsistency in the language. But with
> some practice you learn it.
>
> > You could imagine that if
> > Python had had (character) sets from the start then 'split' and
> > 'strip' could have accepted a string or a set depending on whether you
> > wanted to split on or stripping off a string or a set.
>
> Too bad you haven't suggested this when they were designing Python
> 3 :-)
> This may be suggested for Python 3.1.
>
I might also add that str.startswith can accept a tuple of strings;
shouldn't that have been a set? :-)

I also had the thought that the backtick (`), which is not used in
Python 3, could be used to form character set literals (`aeiou` =>
set("aeiou")), although that might only be worth while if character
sets were introduced as an specialised form of set.



More information about the Python-list mailing list