擅长:python、mysql、java
<p>我想这是意料之中的结果,但我不确定是否有一个简单的方法来使用理解。你知道吗</p>
<pre><code>books = [{'author':'Joyce', 'novel': 'Dubliners'},
{'author':'Greene','novel':'The End of the Affair'},
{'author':'JD Salinger','novel':'Catcher in the Rye'}]
nbooks = {}
for book in books:
author = book['author']
novel = book['novel']
nbooks.setdefault(author, []).append(novel)
print(nbooks['Joyce'])
</code></pre>