Skip to content

Instantly share code, notes, and snippets.

@1ockwood
Last active August 2, 2023 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1ockwood/ae2172723d67deb11f13ef4f975dcd5d to your computer and use it in GitHub Desktop.
Save 1ockwood/ae2172723d67deb11f13ef4f975dcd5d to your computer and use it in GitHub Desktop.
Rendezvous with Cassidoo Newsletter #311 - Interview Question of the Week
# Rendezvous with Cassidoo Newsletter #311 - Interview Question of the Week
# https://buttondown.email/cassidoo/archive/science-is-organized-knowledge-wisdom-is/
# Question:
# Given two strings s and t, return true if t is an anagram of s, and false otherwise.
# Try this in a language you're not comfortable with!
def is_anagram(word_1, word_2):
# convert the words to lowercase, remove any spaces, and sort the characters
# if the results match, word_2 is an anagram of word_1 (and vice versa)
return sorted(word_1.lower().replace(' ', '')) == sorted(word_2.lower().replace(' ', ''))
# test examples from the newsletter
print(is_anagram('barbie', 'oppenheimer')) # Should output False
print(is_anagram('race', 'care')) # Should output True
print(is_anagram('anagram', 'nag a ram')) # Should output True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment