Most Frequent Word in Strings List Last Updated : 05 Feb, 2025 Comments Improve Suggest changes Like Article Like Report We are given a list of strings we need to find the most frequent words from that particular list. For example, w = ["apple", "banana", "apple", "orange", "banana", "apple"] we need to find most frequent words in list which is 'apple' in this case.Using Counter from collectionsCounter class from the collections module counts occurrences of words in list. Using Counter.most_common(1) we can retrieve most frequent word along with its count. Python from collections import Counter # Define a list of words w = ["apple", "banana", "apple", "orange", "banana", "apple"] # Use Counter to count occurrences of each word and get the most common word f = Counter(w).most_common(1)[0][0] print(f) Outputapple Explanation:Counter(w) creates a dictionary-like object that counts occurrences of each word, and most_common(1) returns a list with most frequent word and its count.[0][0] extracts the most frequent word from tuple.Using a DictionaryWe can use a dictionary to manually count word occurrences by iterating through list and updating count for each word with highest count is then identified by checking maximum value in dictionary. Python w = ["apple", "banana", "apple", "orange", "banana", "apple"] f = {} for word in w: f[word] = f.get(word, 0) + 1 # Increment count for each word # Find the word with the highest frequency m = max(f, key=f.get) print(m) Outputapple Explanation:Dictionary f stores word counts using f.get(word, 0) + 1 to update occurrences for each word in list.max(f, key=f.get) finds the word with the highest frequency by selecting key with maximum count.Using collections.defaultdictdefaultdict from the collections module simplifies counting by initializing missing keys with a default value. We can use it to store word frequencies and find most frequent word using max(). Python from collections import defaultdict w = ["apple", "banana", "apple", "orange", "banana", "apple"] freq = defaultdict(int) for word in w: freq[word] += 1 f = max(freq, key=freq.get) print(f) Outputapple Explanation:defaultdict(int) automatically initializes missing keys with a default value of 0 making it easier to count word occurrences without checking for key existence.max(freq, key=freq.get) finds word with highest count by selecting key with maximum value. Comment More infoAdvertise with us Next Article Most Frequent Word in Strings List M manjeet_04 Follow Improve Article Tags : Python Python Programs Python list-programs Python string-programs Practice Tags : python Similar Reads Python - List Words Frequency in String Given a List of Words, Map frequency of each to occurrence in String. Input : test_str = 'geeksforgeeks is best for geeks and best for CS', count_list = ['best', 'geeksforgeeks', 'computer'] Output : [2, 1, 0] Explanation : best has 2 occ., geeksforgeeks 1 and computer is not present in string.Input 4 min read Python | Extract Nth words in Strings List Sometimes, while working with Python Lists, we can have problems in which we need to perform the task of extracting Nth word of each string in List. This can have applications in the web-development domain. Let's discuss certain ways in which this task can be performed. Method #1: Using list compreh 7 min read Prefix frequency in string List - Python In this article, we will explore various methods to find prefix frequency in string List. The simplest way to do is by using a loop.Using a LoopOne of the simplest ways to calculate the frequency of a prefix in a list of strings is by iterating through each element and checking if the string starts 2 min read Python | Find k longest words in given list Given a list of words and a positive integer K, write a Python program to find k longest words in the list in descending order of length. Examples: Input : lst = ['am', 'watermelon', 'girl', 'boy', 'colour'], K = 3 Output : ['watermelon', 'colour', 'girl'] Input : ['see', 'I', 'geek', 'on', 'brain'] 5 min read Python | Frequency of substring in given string Finding a substring in a string has been dealt with in many ways. But sometimes, we are just interested to know how many times a particular substring occurs in a string. Let's discuss certain ways in which this task is performed. Method #1: Using count() This is a quite straightforward method in whi 6 min read Like