Re: split() and string.whitespace
- From: MRAB <google@xxxxxxxxxxxxxxxxxxx>
- Date: Tue, 4 Nov 2008 15:49:45 -0800 (PST)
On Nov 4, 8:00 pm, bearophileH...@xxxxxxxxx wrote:
MRAB:I might also add that str.startswith can accept a tuple of strings;
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.
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.
.
- Follow-Ups:
- Re: split() and string.whitespace
- From: bearophileHUGS
- Re: split() and string.whitespace
- References:
- Re: split() and string.whitespace
- From: bearophileHUGS
- Re: split() and string.whitespace
- Prev by Date: Re: Is there a better/simpler way to filter blank lines?
- Next by Date: Re: locating the chorus in a MIDI song?
- Previous by thread: Re: split() and string.whitespace
- Next by thread: Re: split() and string.whitespace
- Index(es):
Relevant Pages
|