Currently I am trying to get words such as "The quick brown fox jumped over the lazy brown dog’s back" read from a text file and organized by word length and by word count.
So the output should be:
1 The
1 fox
1 the
1 back
1 lazy
1 over
2 brown
1 dog’s
1 quick
1 jumped
I did check quite a lot of stackoverflow questions like how to sort by length of string followed by alphabetical order?, and I'm going to guess I missed it, or I don't understand how to use it. I'm a beginner with python.
This is what I have so far:
from collections import Counter
file = open("text.txt","r")
#read the file & split words
wordcount =Counter(file.read().split())
#printing word count
for item in wordcount.items():
print ("{}\t{}".format(*item))
Could someone help me know what i'm doing wrong?