I have to count the word frequency in a text using python. I thought of keeping words in a dictionary and having a count for each of these words.
Now if I have to so
There are few steps involved in this Problem :
Sort the Array Based on Frequency.
def wordCount(self,nums):
nums = "Hello, number of transaction which happened, for,"
nums=nums.lower().translate(None,string.punctuation).split()
d = {}
for i in nums:
if i not in d:
d[i] = 1
else:
d[i] = d[i]+1
sorted_d = (sorted(d.items(), key = operator.itemgetter(1), reverse = True)
for key,val in sorted_d:
print key,val