このページでこのインタビューの質問に出くわしました: (http://newworld-alex.blogspot.com/2009/03/facebook-interviewzz.html)
技術的な質問: Python で、ある単語の文字バリエーションの辞書が与えられた場合、たとえば dictChars = {"e" : [E, 3], "x" : [X], "a" : [A, @], "m " : [M]}パスワード クラッカーのような部分的な文字列順列ジェネレータを実装します。つまり、exaM、exAm、exAM、ex@m、... を生成します。Python で単純な 3 行の再帰ソリューションを実装しました。
私はPythonで解決策を持っていますが、彼のように3行にする方法がわかりません。
参考までに、これが私の現在の解決策です:
def allPossiblePasswords(password, mapping):
if len(password) == 0:
return [""]
else:
next = allPossiblePasswords(password[1:], mapping)
if password[0] in mapping:
return [c + n for c in mapping[password[0]] for n in next]
else:
return [password[0] + n for n in next]
前もって感謝します!