私はこれを使用して問題を解決しました(ひどく非効率的な方法):
def createList(word, wordList):
#Made a set, because for some reason permutations was returning duplicates.
#Returns all permutations if they're in the wordList
return set([''.join(item) for item in itertools.permutations(word) if ''.join(item) in wordList])
def main():
a = open('C:\\Python32\\megalist.txt', 'r+')
wordList = [line.strip() for line in a]
maximum = 0
length = 0
maxwords = ""
for words in wordList:
permList = createList(words, wordList)
length = len(permList)
if length > maximum:
maximum = length
maxwords = permList
print (maximum, maxwords)
辞書で有効なアナグラムが最も多い5文字の単語を見つけるのに10分ほどかかりました。文字の制約のない単語でこれを実行したいのですが、ばかげた時間がかかります。これを最適化する方法はありますか?