KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
The following code prints out the word in the txt file and then how many instances there are of that word (e.g. a, 26) the problem is that it doesn't print it out in alphabetical order. Any help would be much appreciated import re def print_word_counts(filename): s=open(filename).read() words=re.findall('[a-zA-Z]+', s) e=[x.lower() for x in (words)] e.sort() from collections import Counter dic=Counter(e) for key,value in dic.items(): print (key,value) print_word_counts('engltreaty.txt')
Tags (comma-separated)
Save Edits
Cancel