I'm opening two files, one is a text, and the other is a list. I'm wanting through for nested to check how many times each list item appears in the text.
I did so:
arquivo = open('texto.txt', 'r')
lista = open('lista.txt', 'r')
for item in lista:
i = 0;
for linha in arquivo:
if item[0:-1] in linha:
i += 1
print(item)
print(i)
But that way he's only showing the first item on the list and how often it appears. For example, if you have the word 'iPhone 6' in my list and it appears 3 times in the text, it gives this output:
iPhone 6
1
iPhone 6
2
iPhone 6
3