【发布时间】:2014-04-13 19:06:26
【问题描述】:
我为字谜编写了代码,但它没有给出某些测试用例的结果
import itertools
def find_all_anagrams(words, word):
if word is None:
return []
else:
m = set()
for permutation in itertools.permutations(word.lower()):
m.add("".join(permutation))
ls = []
for anagram in m:
ls.append(anagram)
n = [i for i in words if i in ls]
return n
pass
assert ["not", "ton"] == find_all_anagrams(["ant", "not", "ton"], "ont")
assert ["ant", "tan"] == find_all_anagrams(["ant", "not", "ton", "tan"], "tan")
assert [] == find_all_anagrams(["ant", "not", "ton", "tan"], "abc")
assert [] == find_all_anagrams(["ant", "not", "ton", "tan"], None)
assert [] == find_all_anagrams(None, None)
assert ["ant", "tan"] == find_all_anagrams(["ant", "not", "ton", "tan"], "TAN")
但是对于这个测试用例,它给出了一个空列表
assert ["Ant", "Tan"] == find_all_anagrams(["Ant", "not", "ton", "Tan"], "TAN")
检查我的代码
【问题讨论】: