Writing prefix count into a txt file using python

The problem with your code is that you seem to don't know how to read a file.


If you want to read a file with Python, you have to use the open built-in function, this way:

with open('file.txt', 'r+') as file: #'r+' stands for read+
    text = file.read()

Then I would count this way the 'prefixes':

for i in text:
    if (text.count(i) >= 1000):
        # Do something