77 961
Assignments Done
Successfully Done
In August 2019

Answer to Question #43113 in Python for shami

Question #43113
Write a class/function to return True if 2 input strings are anagram to each other. string1 is an anagram of string2 if string2 can be obtained by rearranging the characters in string1. Example:
string1 = ‘smart’, string2 = ‘marts’  result = True
string1 = ‘secure’, string2 = ‘rescue’  result = True
Expert's answer
# Answer on Question #43113 - Programming - Python
from collections import Counter
def anagrams(s1, s2):
return Counter(s1) == Counter(s2)
def test():
assert anagrams('', '')
assert anagrams('a', 'a')
assert not anagrams('a', 'b')
assert anagrams('smart', 'marts')
assert anagrams('secure', 'rescue')
assert not anagrams('secure', 'rescu')
assert anagrams('abcabc', 'aabbcc')
print "Tests passed"

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions