查找字谜的最佳算法

时间:2019-06-09 07:27:32

标签: python python-3.x

需要一些帮助来优化找到字谜并进行相应打印的最佳方法。

def findinganagrams1(arr):
i = 0
seen = set()
match = []
matching = []
finalset = []
lastset = []

for word in arr[::]:
    if sorted(arr[i]) == sorted(word) and word not in seen:
        match.append(word)
    else:
        matching.append(word)

for word in matching[::]:
    if sorted(matching[i]) == sorted(word) and word not in seen:
        finalset.append(word)
    else:
        lastset.append(word)

print(match)
print(finalset)
print(lastset)

0 个答案:

没有答案