Problem Statement
What is the most Pythonic way to check if two strings are anagrams?
Explanation
Anagrams have the same character counts. Counter compares frequency maps in linear time. Sorting also works but is O(n log n) and less direct.
Comparing sets fails because it ignores frequencies. Reversing does not relate to anagrams.
Code Solution
SolutionRead Only
from collections import Counter
def is_anagram(a,b):
return Counter(a) == Counter(b)