I have a text and am trying to extract the 10 most frequent words in it. I use the text.most_common(10) method, but am getting the ouput in form of a tuple which also contains the number of occurencies (which I don't need...). How can I fix this so that the output is just the words in form of a list?
Note: I can't use the nltk library in the program to be created.
this is the code I wrote:
tuple(map(str, Counter(text).most_common(10)))
this is the output I am getting:
('science', 55)
this is the output I need:
["science"]
You need to get the first item in the pairs returned by
Counter.most_common().Full demo:
gives