擅长:python、mysql、java
<p>这将计算最佳匹配密钥:</p>
<pre><code>def get_best_key(jarvis_fct, words):
priority = 0
best_string = ""
if len(words) == 0:
return "", 0
for i in range(0, len(words)+1):
phrase = " ".join(str(x) for x in words[0:i])
new_priority = len(words[0:i])
if phrase in jarvis_fct and new_priority > priority:
priority = new_priority
best_string = phrase
new_words = words[1:len(words)]
phrase, new_priority = get_best_key(jarvis_fct, new_words)
if new_priority > priority:
priority = new_priority
best_string = phrase
return best_string, priority
while True:
command = input("Awaiting orders \n")
key = get_best_key(jarvis_functions, command.split()))[0]
</code></pre>