a splitting headache
gallium.arsenide at gmail.com
Thu Oct 22 06:21:25 CEST 2009
On Oct 21, 5:43 pm, Mensanator <mensana... at aol.com> wrote:
> >>> '010000110'.split('0')
> ['', '1', '', '', '', '11', '']
> is a perfect example. It shows the empty strings
> generated from the leading and trailing delimiters,
> and also that you get 3 empty strings between the
> '1's, not 4. When creating documentation, it is
> always a good idea to document such cases.
It's documented. It's even in the example (that you cited yourself):
'1,,2'.split(',') returns ['1', '', '2']
There are two commas between the '1' and the '2', but "only" one empty
string between them. To me, it's obvious that
is equivalent to
> And you'll then want to compare this to the
> equivalent whitespace case:
> >>> ' 1 11 '.split()
> ['1', '11']
The documentation could not be more explicit that when the separator
is not specified or is None, it behaves very differently.
Have you tried to see what happens with
' 1 11 '.split(' ')
(Hint: The separator is (a kind of) white space... yet IS specified.)
> I was looking for some feedback here.
> And it seems that no one else considers the
> documentation wanting.
This particular section of documentation, no. I have issues with some
of the documentation here and there; this is not one of those areas.
You kept using phrases in your arguments like "Yes, if you
think it through" and "An example would at least force me to think
about it". Um... are we not supposed to think?
More information about the Python-list