Skip to content

Instantly share code, notes, and snippets.

@sahasourav17
Created January 14, 2022 16:59
Show Gist options
  • Save sahasourav17/eee8e3281fafd0cb2401e7764673c266 to your computer and use it in GitHub Desktop.
Save sahasourav17/eee8e3281fafd0cb2401e7764673c266 to your computer and use it in GitHub Desktop.
from collections import Counter
def anagrams(s1,s2):
"""
As seen in method 2, we first check if both strings have the
same length because if they're not it's impossible for them
to be anagrams.
"""
if len(s1) != len(s2):
return False
#comparing dictionaries with equality operator
return Counter(s1) == Counter(s2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment