- Related Questions & Answers
- Python program to find the size of the largest subset of anagram words
- Program to find length of longest anagram subsequence in Python
- Program to find the largest product of two distinct elements in Python
- Program to find maximum length of non-sharing words in Python
- Program to find largest of three numbers - JavaScript
- Python Program for Find largest prime factor of a number
- C++ Program to Find Size of the Largest Independent Set(LIS) in a Given a Binary Tree
- Program to find the largest grouping of anagrams from a word list in Python
- Program to find largest sum of any path of a binary tree in Python
- Program to find largest sum of non-adjacent elements of a list in Python
- Find largest document size in MongoDB?
- C++ Program to Find Largest Element of an Array
- Python Program to find the largest element in an array
- Python program to find the largest number in a list
- C Program to find size of a File

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Given a lowercase array. Our task is to find the size of the largest subset of string which is an anagram of each other. Anagram of the 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.

Step 1: Split input string separated by space into words. Step 2: sort each string in given list of strings Step 3: now create a dictionary using a counter method which will have strings as key and their Frequencies as value. Step 4: get maximum value of frequency using max function.

# 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 a dictionary using the counter method # which will have strings as key and their # frequencies as the 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)

Enter the string ::>qwe ewq rty ytr ytr ytr The Size Of largest subset of Anangram word is ::> 4

Advertisements