

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python program to find the size of the largest subset of anagram words
Given a lowercase array. Our task is to find the size of largest subset of string which are anagram of each other’s. Anagram of string means one string is an anagram of another if the second is simply a rearrangement of the first. Here we can solve this problem quickly in python using Counter() method.
For example, the strings 'python' and 'typhon' are anagrams.
Algorithm
Step 1: Split input string separated by space into words. Step 2: Sort each string in given list of strings. Step 3: Now create dictionary using counter method which will have strings as key and their Frequencies as value. Step 4: Get maximum value of frequency using max function.
Example code
# Function to find the size of largest subset # of anagram words from collections import Counter def largestana(str1): # split input string separated by space str1 = str1.split(" ") # sort each string in given list of strings for i in range(0,len(str1)): str1[i]=''.join(sorted(str1[i])) # now create dictionary using counter method # which will have strings as key and their # frequencies as value newstr1 = Counter(str1) # get maximum value of frequency print ("The Size Of largest subset of Anangram word is ::>",max(newstr1.values())) # Driver program if __name__ == "__main__": str1 = input("Enter the string ::>") largestana(str1)
Output
Enter the string ::> qwe ewq rty ytr ytr ytr The Size Of largest subset of Anangram word is ::> 4
- Related Questions & Answers
- Python program to find the size of largest subset of anagram words
- C++ Program to find the Largest Divisible Pairs Subset
- Program to find out the minimum size of the largest clique in a graph (Python)
- C++ Program to find the Largest Divisible Subset in Array
- Python program to Find the size of a Tuple
- Program to find length of longest anagram subsequence in Python
- Program to find the sum of largest K sublist in Python
- Program to Find Out the Strings of the Same Size in Python
- Program to find largest average of sublist whose size at least k in Python
- Program to find length of the largest subset where one element in every pair is divisible by other in Python
- Program to find the largest product of two distinct elements in Python
- C++ Program to Find Size of the Largest Independent Set(LIS) in a Given a Binary Tree
- Python program to find word score from list of words
- Python Program to return the Length of the Longest Word from the List of Words
- Program to find largest merge of two strings in Python
Advertisements