[Python-ideas] New explicit methods to trim strings

Kirill Balunov kirillbalunov at gmail.com
Sun Mar 31 05:22:23 EDT 2019


Sorry one more time (it is early morning and I should drink a cup of coffee
first before posting here). Of course it should be `tuple(sorted(('al',
'ical'), key=len, reverse=True))`, I hope it was obvious to everyone from
the very beginning.

with kind regards,
-gdg

вс, 31 мар. 2019 г. в 11:53, Kirill Balunov <kirillbalunov at gmail.com>:

>
>
> вс, 31 мар. 2019 г. в 11:45, Kirill Balunov <kirillbalunov at gmail.com>:
>
>>
>>
>> вс, 31 мар. 2019 г. в 11:36, Steven D'Aprano <steve at pearwood.info>:
>>
>>> There's a slight problem with that: what happens if more than one suffix
>>> matches? E.g. given:
>>>
>>>     "musical".lcut(('al', 'ical'))
>>>
>>> should the suffix "al" be removed, leaving "music"? (First match wins.)
>>>
>>> Or should the suffix "ical" be removed, leaving "mus"? (Longest match
>>> wins.)
>>>
>>>
>> I think you should choose  "First match wins", because in this case you
>> can make "Longest match wins" as `"musical".lcut(tuple(sorted(('al,
>> 'ical'))))`. But if you choose "Longest match wins" there is no chance
>> to achieve "First match wins" behaviour.
>>
>> with kind regards,
>> -gfg
>>
>
> Sorry it should be `.rcut` instead of `.lcut`  in `"musical".*rcut*(tuple(sorted(('al,
> 'ical'))))` at the first place. I will prefer names `.lstrip` and `.rstrip`
> instead of *cut versions.
>
> with kind regards,
> -gdg
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190331/53258333/attachment.html>


More information about the Python-ideas mailing list