Python - Anagrams
Check For Anagrams
- This has to be the easiest way ever to check for anagram.
This ditti imports the collections
library and uses sets.
from collections import Counter
def is_anagram(word1, word2):
"""Checks whether the words are anagrams.
word1: string
word2: string
returns: boolean
"""
return Counter(str1) == Counter(str2)
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.