Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use python and write code for problem. 51. Anagrams An anagram of a word or phra

ID: 3843924 • Letter: U

Question

Use python and write code for problem.

51. Anagrams An anagram of a word or phrase is another word or phrase that uses the same letters with the same frequency. Punctuation marks, case, and spaces are ignored Some examples of anagram pairs are "angered "enraged" and "A gentleman" "Elegant man". Write a program that requests two words or phrases as input and determines if they are anagrams of each other. See Fig. 4.13. The program should use a Boolean valued function with header def areAnagrams (stringl string2) that returns True when the two strings are anagrams, and otherwise returns False.

Explanation / Answer

Answer for Question:

We can use the magic Counter from collections library. With the Help of Counter we will let to know that given two string are Anagrams or not.

It is an unordered collection where elements are stored as dictionary keys and their counts are stored as dictionary values
So, you can initialize a Counter object with a string (a iterable) and compare with another Counter from a string

from collections import Counter

str1 = input("Please enter a word:")
str2 = input("Please enter another word:")

def is_anagram(str1, str2):
return Counter(str1) == Counter(str2)