I am attempting to run a program that will find a new value for A if there is a period contained within a certain index range of it. The problem is, in order to determine the domain of the search, it is necessary to have the words separated within a list, such as this (‘A’, ‘B.’, ‘C’, ‘D’, ‘E’, ‘F’, ‘G’, ‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’, ‘G’). The object is to get the program to find the first A, search the smaller list (‘A B. C D’) for a ‘.’ and, if it finds one, to assign the variable to the next instance of A. All of the code works so far, except for finding the ‘.’ with an in operator, because it is treating it as ‘B.’ . This would not work in application, as ‘B’ wil not be known.
Is there any way to search for a ‘.’ even if it appears next to unknown text? I have attempted using regular expressions, but it is not responding well. This is probably a result of an error on my part.
words = 'A B. C D E F G A B C D E F G A B C D E F G A B C D E F G' corpus = words.split() index_A = corpus.index('A') while '.' in corpus[index_A : index_A + 3]: # This does not seem to be picking up the '.' in 'b.' in isolation. It will find # 'B.' but not '.' from corpus. index_A = corpus.index('A', index_A+1)