Skip to content

Home

String is anagram

Checks if a string is an anagram of another string (case-insensitive, ignores spaces, punctuation and special characters).

from collections import Counter

def is_anagram(s1, s2):
  return Counter(
    c.lower() for c in s1 if c.isalnum()
  ) == Counter(
    c.lower() for c in s2 if c.isalnum()
  )

is_anagram('#anagram', 'Nag a ram!')  # True

More like this

Start typing a keyphrase to see matching snippets.