私はこの機能に少し問題があります。9文字のすべての順列を見つける
def check_possible(input):
possibilities = []
solutions = []
dict = dictionary(input)
dict.get_dict()
words = dict.get_all_words()
for L in range(0, len(input)+1):
for subset in itertools.permutations(input, L):
possibilities.append(subset)
for possibility in possibilities:
poss = "".join(possibility)
if len(poss) > 3 and len(poss) < 9:
for item in words:
for i in item:
if poss in i:
solutions.append(poss)
return solutions
は基本的には、パラメータとして9つの文字でリストを取り、そして3及び9文字の間であり、辞書にある利用可能なすべての順列のリストを生成する(26個の辞書ファイルを使用して、各文字のための1、作成しますリスト内に与えられた各文字のサブリスト、次に上記の関数によって生成されたすべての置換をチェックする)。
ので、この関数は返す必要があります:
>>input = ['a', 'b', 'd', 'c', 'e', 'b', 'd', 'e', 'f']
<<['dace', ..., 'face', 'decaf', 'bedad', 'ceded', 'faded', 'faced', 'beaded', 'deface', 'decade', 'defaced']
この作品、およびそれが正しい値を返しますが、それは10の間になります - 完了するまでに15分。私は同じ結果を達成する方法があるが、より短い時間(好ましくは、1分以内)であるかどうか疑問に思います。
関数内にないときに 'return'は何をしますか? –
私の謝罪は、それは機能にあると考えられていた。 – Notgivinit
[itertools.permutations()](https://docs.python.org/2/library/itertools.html#itertools.permutations)があなたのために作業を行うことができます。ドライ! –