[Python-ideas] This seems like a wart to me...

Bruce Leban bruce at leapyear.org
Fri Dec 12 02:08:24 CET 2008


-inf

That breaks existing code in two different ways which I don't think makes it
easy.

it does NOT collapse adjacent characters:
        >>> "a&&b".split("&")
        ['a', '', 'b']

the separator it splits on is a string, not a character:
        >>> "a<b><c>d".split("><")
        ['a<b', 'c>d']

--- Bruce

On Thu, Dec 11, 2008 at 4:38 PM, Ron Adam <rrr at ronadam.com> wrote:

>
>
> Bruce Leban wrote:
>
>> I think string.split(list) probably won't do what people expect either.
>> Here's what I would expect it to do:
>>
>>  >>> '1 (123) 456-7890'.split([' ', '(', ')', '-'])
>> ['1', '', '123', '', '456', '7890']
>>
>> but what you probably want is:
>>
>>  >>>re.split(r'[ ()-]*', '1 (123) 456-7890')
>> ['1', '123', '456', '7890']
>>
>> using allows you to do that and avoids ambiguity about what it does.
>>
>> --- Bruce
>>
>
> Without getting into regular expressions, it's easier to just allow
> adjacent char matches to act as one match so the following is true.
>
>    longstring.splitchars(string.whitespace)  =  longstring.split()
>
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20081211/46ecca35/attachment.html>


More information about the Python-ideas mailing list