On 19May2020 15:43, David Mertz <mertz@gnosis.cx> 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 <cs@cskk.id.au>