I don't see what trim() is good for but I know I've written ltrim() hundreds of 
times easy. 

I propose naming them strip_prefix() and strip_suffix() and just skip the one 
that does both sides since it makes no sense to me. 

Trim is generally a bad name because what is called strip() in python is called 
trim() in other languages. This would be needlessly confusing. 

> On 24 Mar 2019, at 09:42, Alex Grigoryev <evr...@gmail.com> wrote:
> 
> Following the discussion here I propose to add 3 new string methods: 
> str.trim, str.ltrim, str.rtrim
> Another option would be to change API for str.split method to work correctly 
> with sequences.
> 
> In [1]: def ltrim(s, seq):
> 
>    ...:     return s[len(seq):] if s.startswith(seq) else s
> 
>    ...:
> 
> 
> 
> In [2]: def rtrim(s, seq):
> 
>    ...:     return s[:-len(seq)] if s.endswith(seq) else s
> 
>    ...:
> 
> 
> 
> In [3]: def trim(s, seq):
> 
>    ...:     return ltrim(rtrim(s, seq), seq)
> 
>    ...:
> 
> 
> 
> In [4]: s = 'mailto:ma...@gmail.com'
> 
> 
> 
> In [5]: ltrim(s, 'mailto:')
> 
> Out[5]: 'ma...@gmail.com'
> 
> 
> 
> In [6]: rtrim(s, 'com')
> 
> Out[6]: 'mailto:maria@gmail.'
> 
> 
> 
> In [7]: trim(s, 'm')
> 
> Out[7]: 'ailto:ma...@gmail.co'
> 
> 
> _______________________________________________
> Python-ideas mailing list
> Python-ideas@python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to