def word_count(str):
counts = dict()
words = str.split()
for word in words:
if word in counts:
counts[word] += 1
else:
counts[word] = 1
return counts
print(word_count("""the quick brown fox jumps over the lazy lazy lazy dog."""))
Output:
{'the': 2, 'quick': 1, 'brown': 1, 'fox': 1, 'jumps': 1, 'over': 1, 'lazy': 3, 'dog.': 1}
But I want two Output, one like this:
{3 : 'lazy',2 :'the',1 : 'quick',1 : 'brown',1 : 'fox',1 : 'jumps',1 : 'over',1 : 'dog'}
An the other like this organize alphabetically:
['brown' : 1,'dog.' : 1,'fox' : 1,'jumps' 1: ,'lazy' 3: , 'over': 1,'quick' 1: ,'the' : 2]
I know that with sorted it can organize alphabetically but I don`t know how to pt it together with the result. I was looking all over Stack-overflow and other places to see if I can find any result but I could not find anything.