count most frequent words in list python

Solutions on MaxInterview for count most frequent words in list python by the best coders in the world

showing results for - "count most frequent words in list python"
Audrina
07 Jan 2017
1from collections import Counter
2
3data_set = "Welcome to the world of Geeks " \
4"This portal has been created to provide well written well" \
5"thought and well explained solutions for selected questions " \
6"If you like Geeks for Geeks and would like to contribute " \
7"here is your chance You can write article and mail your article " \
8" to contribute at geeksforgeeks org See your article appearing on " \
9"the Geeks for Geeks main page and help thousands of other Geeks. " \
10
11# split() returns list of all the words in the string
12split_it = data_set.split()
13
14# Pass the split_it list to instance of Counter class.
15Counters_found = Counter(split_it)
16#print(Counters)
17
18# most_common() produces k frequently encountered
19# input values and their respective counts.
20most_occur = Counters_found.most_common(4)
21print(most_occur)
22