On 19May2020 15:43, David Mertz <[email protected]> wrote:
I may be misunderstanding, but it sounds like = is not acceptable in the
final result, so it's not enough to remove only 2 of 4 ='s. You want to
make sure nothing messed up your string. So if the code existed, what you'd
want is:


```
assert salt.count("=") <= 2
salt = salt.rstrip("=", "")
assert "=" not in salt
```


I think the code I'd want, if the new parameter existed, would be:

salt = salt.rstrip("=", maxstrip=2)
assert not salt.endswith("=")

Reiterating the Python 3.9 suggestion, what about:

 salt2 = salt.cutsuffix(('==', '='))

I appreciate this isn't as _general_ as a maxstrip param, but it seems to neatly address the single use case you've found.

Cheers,
Cameron Simpson <[email protected]>
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/SERQXAUI22ARP5BTBGJ6AAS7KQVBNTUJ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to