-
-
Save 1ockwood/ae2172723d67deb11f13ef4f975dcd5d to your computer and use it in GitHub Desktop.
Rendezvous with Cassidoo Newsletter #311 - Interview Question of the Week
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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