so I'm pretty much a beginner and I have to go through this exercise whom task is to print the top 10 words in a given file. Now, this is how my code looks so far:
file = input("Enter a file ")
sfile = open(file)
alphabet = ["a","b","c","d","e","f","g","h","i","j","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
w_ords= dict()
for line in sfile :
line=line.strip()
words = line.split()
for letter in words:
letter = [words]
for letter in alphabet :
w_ords[letter] = w_ords.get(letter, 0)+ 1
print(sorted([(b,a[:10]) for a,b in w_ords.items()], reverse = True))
the problem is that my output looks like this
[(4910, 'z'), (4910, 'y'), (4910, 'x'), (4910, 'w'), (4910, 'v'), (4910, 'u'), (4910, 't'), (4910, 's'), (4910, 'r'), (4910, 'q'), (4910, 'p'), (4910, 'o'), (4910, 'n'), (4910, 'm'), (4910, 'l'), (4910, 'j'), (4910, 'i'), (4910, 'h'), (4910, 'g'), (4910, 'f'), (4910, 'e'), (4910, 'd'), (4910, 'c'), (4910, 'b'), (4910, 'a')]
what am I doing wrong? the dividing into letters kinda works the problem is that it doesn't count them as unique letters I guess.