Given a List of Strings, find frequency of strings case insensitive.
Input : test_list = [“Gfg”, “Best”, “GFG”, “is”, “IS”, “BEST”]
Output : {‘gfg’: 2, ‘best’: 2, ‘is’: 2}
Explanation : All occur twice.Input : test_list = [“Gfg”, “gfg”, “GFG”]
Output : {‘gfg’: 3}
Explanation : Only “gfg” 3 occurrences.
Method : Using defaultdict() + lower()
In this, we perform lower() to all the strings, before mapping in defaultdict. This ensures case insensitivity while mapping and cumulating frequency.
Python3
# Python3 code to demonstrate working of # Strings Frequency (Case Insensitive) # Using defaultdict() + lower() from collections import defaultdict # initializing list test_list = ["Gfg", "Best", "best", "gfg", "GFG", "is", "IS", "BEST"] # printing original list print("The original list is : " + str(test_list)) res = defaultdict(int) for ele in test_list: # lowercasing to cater for Case Insensitivity res[ele.lower()] += 1 # printing result print("Strings Frequency : " + str(dict(res))) |
The original list is : ['Gfg', 'Best', 'best', 'gfg', 'GFG', 'is', 'IS', 'BEST']
Strings Frequency : {'gfg': 3, 'best': 3, 'is': 2}
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
Recommended Posts:
- Python - Counter.items(), Counter.keys() and Counter.values()
- Case-insensitive string comparison in Python
- Python | Ways to sort list of strings in case-insensitive manner
- Python - Case Insensitive Strings Grouping
- Python | Case Counter in String
- Python program to convert camel case string to snake case
- Python - Convert Snake Case String to Camel Case
- Python regex to find sequences of one upper case letter followed by lower case letters
- Python - Convert Snake case to Pascal case
- Python counter and dictionary intersection example (Make a string using deletion and rearrangement)
- Anagram checking in Python using collections.Counter()
- Python dictionary, set and counter to check if frequencies can become same
- Python | Minimum number of subsets with distinct elements using Counter
- Python Counter to find the size of largest subset of anagram words
- Python Counter| Find duplicate rows in a binary matrix
- Python Counter | Majority Element
- Python | Counter Objects | elements()
- Operations on Python Counter
- Python - Occurrence counter in List of Records
- Python - Matrix elements Frequencies Counter
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

