bvr's answer will address the immediate needs of the problem.
A recommendation is to use exists instead of defined to check if the string is present in the dictionary. This will ensure that non-words such as 'bemyg' will never become keys in the dictionary hash.
发布评论
评论(2)
只需将
find_words
中的print
替换为对变量的赋值,并在for
循环结束后打印它。Simply replace
print
infind_words
with an assignment into variable and print it after thefor
loop ends.bvr的答案将解决问题的直接需求。
建议使用
exists
而不是define
检查字符串是否存在于字典中。这将确保诸如'bemyg'
这样的非单词永远不会成为字典哈希中的键。bvr's answer will address the immediate needs of the problem.
A recommendation is to use
exists
instead ofdefined
to check if the string is present in the dictionary. This will ensure that non-words such as'bemyg'
will never become keys in the dictionary hash.