I have a working set of code that iterates through a string and searches for 2 relevant substrings. (shoutout to user @bulbus for the help!)
The code returns a list of tuples containing the index positions for the location of the next instance of each substring.
For example, if the strings and substrings looked like this:
sub_A = "StringA"
sub_B = "StringB"
s = "abcdefStringAghijklStringB"
Then the code returns the tuple (6,19)
because that is the next index position where the two strings exist.
The relevant part of the code looks like this:
[(m.start(),re.compile(sub_b).search(s,m.start()).start()) for m in re.finditer(sub_A,s)]
However, I want to change the code so that it only returns values to the tuple if the value is even. I.E. in my example above the value "19" should not be a valid return.
As an example, let's say this is my new string:
xxStringAStringBStringB
I want the tuple to return (2,16)
. Because those are the next "valid" returns.
My code currently returns (2,9)
but I want to skip the "StringB" at index 9 since it is an odd number.
Thoughts? And thanks!!