On Thu, Oct 14, 2021 at 2:21 AM <2qdxy4rzwzuui...@potatochowder.com> wrote: > > On 2021-10-14 at 00:00:25 +0900, > "Stephen J. Turnbull" <stephenjturnb...@gmail.com> wrote: > > > Chris Angelico writes: > > > > > +1, although it's debatable whether it should be remove suffix or > > > remove all. I'd be happy with either. > > > > If by "remove all" you mean "efefef" - "ef" == "", I think that's a > > footgun. Similarly for "efabcd" - "ef" == "abcdef" - "ef". > > I don't know whether it qualifies as prior art, but in Erlang (a > language emphatically *not* known for its string handling), strings are > lists of codepoints, and the list subtraction operator¹ is spelled "--": > > The list subtraction operator -- produces a list that is a copy of > the first argument. The procedure is a follows: for each element in > the second argument, the first occurrence of this element (if any) > is removed. > > Example: > > 2> [1,2,3,2,1,2]--[2,1,2]. > [3,1,2] > > And from my interactive prompt: > > 4> "abcdef" -- "ef". > "abcd" > 5> "abcdef" -- "ab". > "cdef" > > ¹ http://erlang.org/doc/reference_manual/expressions.html#list-operations
It definitely counts as prior art. Another language that allows string subtraction is Pike: > "abcdef" - "ab"; (1) Result: "cdef" I don't think it's quite such a foot-gun as you might think; but on the other hand, I'm also quite happy to see string subtraction defined in terms of removesuffix, since that IS a closer inverse to string addition. It'd end up being one of those cases where both behaviours are useful, and I'd just have to change gears when coding in multiple languages. (Which has to happen anyway. There's plenty of little differences, like modulo with negative numbers.) ChrisA _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/WSOIV7UMSJUASPLW67VUOVQF326P5EWI/ Code of Conduct: http://python.org/psf/codeofconduct/