Odd listcomp behaviour
Emile van Sebille
emile at fenx.com
Fri Dec 17 18:20:46 EST 2010
On 12/17/2010 3:17 PM Emile van Sebille said...
> On 12/17/2010 3:08 PM Emile van Sebille said...
>> Does anyone else consider this a bug?
>
> Hmmm... looks like it's split that I've got the issue with...
>
Nevermind... if it's documented it's not a bug, right?
Hrrmph.
Emile
str.split([sep[, maxsplit]])ΒΆ
Return a list of the words in the string, using sep as the
delimiter string. If maxsplit is given, at most maxsplit splits are done
(thus, the list will have at most maxsplit+1 elements). If maxsplit is
not specified, then there is no limit on the number of splits (all
possible splits are made).
If sep is given, consecutive delimiters are not grouped together
and are deemed to delimit empty strings (for example, '1,,2'.split(',')
returns ['1', '', '2']). The sep argument may consist of multiple
characters (for example, '1<>2<>3'.split('<>') returns ['1', '2', '3']).
Splitting an empty string with a specified separator returns [''].
If sep is not specified or is None, a different splitting algorithm
is applied: runs of consecutive whitespace are regarded as a single
separator, and the result will contain no empty strings at the start or
end if the string has leading or trailing whitespace. Consequently,
splitting an empty string or a string consisting of just whitespace with
a None separator returns [].
For example, ' 1 2 3 '.split() returns ['1', '2', '3'], and '
1 2 3 '.split(None, 1) returns ['1', '2 3 '].
More information about the Python-list
mailing list