需要一些帮助来优化找到字谜并进行相应打印的最佳方法。
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)