I am trying to write a while-loop within a while-loop, and for some reason it is not working as it should. I know I'm probably missing something really trivial here, but I just don't understand how its not working!
The purpose of the loop is to compare two strings to see whether or not they contain any 3 consecutive words the same. I first split the two strings into lists of their respective 3 word string combinations which I store in the lists strings and stringscompare. Then I loop through each 3 word string in stringscompare for each 3 word string in strings.
This will probably seem like a pretty long way round for some but I am only a novice programmer, any improvements would be greatly appreciated.
So currently, the second while loop runs all the way through, however the first one only loops through once, for the first string in strings. If the string matches I would like it to break from both loops, however these loops are also in a much bigger for loop which I don't want it to break out of.
e.g.
'this is a string'
'this is another string' --no match
'this is a list a strings' -- matches 'this is a'
'the list is a string' -- should match 'is a string' but currently does not
strings = <list of 3 word strings> [...,...,...]
stringscompare = <list of 3 word strings to compare>
v=0, x=0
while v < len(strings) and stop == False:
while x < len(stringscompare) and stop == False:
if re.search(strings[v], stringscompare[x]):
same.append(dict)
stop = True
x += 1
v +=1