I want to compare two lists, if both have the same word with its match number. The match number is important here. I did it in this way;
List1= ['john', 'doe','sima']
List2=[]
test = "John is with Doe but alina is alone today."
List2 = test.lower().split()
n=0
counter=0
while n < len(List1):
for i in range(len(List2)):
if List1[n] == List2[i]:
print("Matched : "+str(counter) + List1[n])
n=n+1
counter=counter+1
else:
print("No match :"+ List1[n])
# break
# break
The program is working fine, if both lists have the matched words. But for unmatched word sima, the loop is running infinite times. If break the for loop in else and then break the while loop just after it as comment is telling in the code, the program run for first match only. Thanks in advance.
Edit 1
while n < len(List1):
for i in range(len(List2)):
# print("Matching :"+ List1[n]+ " : "+ List2[i])
if List1[n] == List2[i]:
print("Matched : "+str(counter) + List1[n])
counter=counter+1
else:
print("No match :"+ List1[n])
n=n+1
Giving IndexError: list index out of range error
counterfor each match. How can I get counter usingsetand&?