Write a program anagram_analysis.py
that has an areAnagrams()
function that takes two strings as parameters, and returns True
if they are anagrams of each other, and False
otherwise.
A template for this program using one possible anagram-checking strategy is given below.
#!/usr/bin/env python3
"""
anagram_analysis.py
A strategy for detecting anagrams by going through each letter in
first word, identifying its occurence in second word, until all letters
have been checked off.
"""
def areAnagrams(word1, word2):
"""takes two words and returns True if they're anagrams
Strategy:
1. Go through every letter in word1.
2. If that letter exists in word2, "cross it out"
3. If we ever find a letter in word1 that we can't cross out
in word2, return false
4. If we successfully cross them all out, return true.
"""
# Convert word2 to a list of letters so we can "cross them out" by
# giving them a value of None
# Append every letter from word2 to the word2list
# Go through every letter in word1
# Set up boolean variable, assume we won't find a matching letter
# Go through every letter in word2
# if letter in word2 matches letter in word1:
# remove the letter in word2 from the list ("cross it off")
# set boolean variable
# If we went through word2 and didn't cross a letter off
# return false, two words must not be anagrams
# return true, words must be anagrams