擅长:python、mysql、java
<p>键已排序,因此我们可以跳过排序</p>
<p>我们可以在<code>" "</code>上拆分键,并在dict中过滤按关联值拆分的键</p>
<pre><code>d = {"How are things going": ["going","How"], "What the hell" : ["What", "hell"], "The police dept": ["dept","police"]}
lists = []
for k in d.keys():
to_replace = k.split(" ")
replaced = filter(lambda x: x in d[k],to_replace)
lists.append(list(replaced))
print(lists)
</code></pre>
<p>输出:</p>
<pre><code>[['How', 'going'], ['What', 'hell'], ['police', 'dept']]
</code></pre>