1
I’m opening two files, one is a text, and the other is a list. I want through nested check how many times each item in the list 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)
Only that way he’s only showing the first item on the list and how many times he shows up. For example, if you have the word 'iPhone 6' in my list and it appears 3 times in the text, it gives that output:
iPhone 6
1
iPhone 6
2
iPhone 6
3