
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python program for most frequent word in Strings List
When it is required to find the most frequent word in a list of strings, the list is iterated over and the ‘max’ method is used to get the count of the highest string.
Example
Below is a demonstration of the same
from collections import defaultdict my_list = ["python is best for coders", "python is fun", "python is easy to learn"] print("The list is :") print(my_list) my_temp = defaultdict(int) for sub in my_list: for word in sub.split(): my_temp[word] += 1 result = max(my_temp, key=my_temp.get) print("The word that has the maximum frequency :") print(result)
Output
The list is : ['python is best for coders', 'python is fun', 'python is easy to learn'] The word that has the maximum frequency : python
Explanation
The required packages are imported into the environment.
A list of strings is defined and is displayed on the console.
A dictionary of integers is created and assigned to a variable.
The list of strings is iterated over and split based on spaces.
The count of every word is determined.
The maximum of these values is determined using the ‘max’ method.
This is assigned to a variable.
This is displayed as output on the console.
- Related Articles
- Find most frequent element in a list in Python
- Python program to find Most Frequent Character in a String
- Finding the most frequent word(s) in an array using JavaScript
- Program to find frequency of the most frequent element in Python
- Program to find most frequent subtree sum of a binary tree in Python
- Program to find second most frequent character in C++
- Python Program to crawl a web page and get most frequent words
- C# program to find the most frequent element
- Python program to find the character position of Kth word from a list of strings
- Most Frequent Subtree Sum in C++
- Python – Test for Word construction from character list
- Find the k most frequent words from data set in Python
- Most Frequent Number in Intervals in C++
- Program to find out the index of the most frequent element in a concealed array in Python
- Most frequent element in an array in C++

Advertisements