Posts: 4,646
Threads: 1,493
Joined: Sep 2016
i need the index of the first occurrence of in
s (at or after index
i) just like
s.index(x,i) but in
reverse. that is, equivalent to testing slices of
s[
i:
i+len(
x)] for a decrementing value of i
.
anyone know of such a method or function? this is for a
str type though a general solution for any
sequence type would be great.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,646
Threads: 1,493
Joined: Sep 2016
does it actually run across str in the reverse direction ... or does it run forward across all matches updating its result variable each time, returning it at the end?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,646
Threads: 1,493
Joined: Sep 2016
it turns out i need to do something odd in my find. i need to include a special code in the string i am looking for that will match a run of any number of white space characters much like str.split() with no arguments splits on. i think i need to make my own find function for this. i'm trying to think how str.split() might optimize this for me. for example if '_' is where the special code is and i am searching for 'foo_bar' then 'xfoo bary' will result in it being found at position 1 with an end of 10. the special code will need to be something extremely unlikely to ever be used or else i'll need to use lists an a non-character for it. i hope Unicode has something.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,646
Threads: 1,493
Joined: Sep 2016
this seems to work when i get down to just comparing a string with the special code to the string with the run of white space:
if look_for.split(special_code) == compare_to.split():
...
i have to be sure not to compare a shorter
compare_to first since then it might have a truncated run of white space (this comparison would be equal for that case, too). if this comparison is true the length of
compare_to needs to be known.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.