import string def change_vowels_for_numbers(astring): """ takes all the vowels in the input and replaces them with numbers: a,A --> 1, e,E --> 2, i,I --> 3, o,O --> 4, u,U -->5 """ result = [] for letter in astring: if letter in 'aA': result.append('1') elif letter in 'eE': result.append('2') elif letter in 'iI': result.append('3') elif letter in 'oO': result.append('4') elif letter in 'uU': result.append('5') else: result.append(letter) return "".join(result) def is_palindrome(astring): """checks whether a string is the same spelled forward or backward.""" return astring == astring[::-1] vowels = 'aAeEiIoOuUyY' consonants = 'bBcCdDfFgGhHjJkKlLmMnNpPqQrRsStTvVxXzZ' def pig_latin(word): if word[0] in vowels: if word[-1] in vowels: return word+'yay' else: return word+'ay' else: #string does not start with a vowel part1 = [] part2 = [] seen_vowel = False for letter in word: if letter in consonants and not seen_vowel: part1.append(letter) else: seen_vowel = True part2.append(letter) return ''.join(part2)+''.join(part1)+'ay' if __name__ == "__main__": test = ['pig', 'latin', 'banana', 'happy', 'smile', 'string', 'store', 'eat', 'omelet', 'egg', 'explain', 'honest'] for word in test: print(word, pig_latin(word)) def is_anagram(one, two): """ checks whether these words are anagrams using sorted lists and very simple Python constructs. """ def make_list(word): result = [] for letter in word: if letter in string.ascii_letters: result.append(letter) return result return sorted(make_list(one))==sorted(make_list(two))