问题:编写一个程序,初始化一个空列表,然后提示用户输入单个单词并不断提示输入单个单词,将每个单词添加到列表中,直到用户输入单个句点字符'。然后打印所有单词对,它们是字谜。比较应该不区分大小写。- 可以简单地使用字典,但不是必需的。可以定义合适的功能。
我已经尝试了以下代码的几个版本,但我似乎无法弄清楚我做错了什么。有人可以帮我指出正确的方向/给我一个类似的示例代码吗?我只是这么卡住。
def areAnagrams(inputList):
"""Return inputList if words are anagrams, False otherwise"""
inputList = sorted(inputList.lower())
return inputList
inputList = raw_input ("Enter a word period to end: ")
list = []
while inputList != '.':
anagram = inputList
list.append(anagram)
inputList = raw_input("Enter a word (period to end): ")
print "Anagrams:", areAnagrams(inputList)