I would like to find the last occurrence of the number of characters in a string.
str.rfind () will give the index of the last occurrence of one character in the string, but I need the index of the last occurrence of any of several characters. For example, if I had a line:
test_string = '([2+2])-[3+4])'
I need a function that returns the index of the last occurrence of {, [, or {similarly
test_string.rfind('(', '[', '{')
Which ideally will return 8. What is the best way to do this?
max(test_string.rfind('('), test_string.rfind('['), test_string.rfind('{'))
seems awkward, not Pythonic.
source share