dict = [{'author':'Joyce', 'novel': 'Dubliners'},
{'author':'Greene','novel':'The End of the Affair'},
{'author':'JD Salinger','novel':'Catcher in the Rye'}]
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'])
你可以使用列表理解
获取所有小说:
我想这是意料之中的结果,但我不确定是否有一个简单的方法来使用理解。你知道吗
如果您正在查找特定作者的所有书籍:
所有小说:
相关问题 更多 >
编程相关推荐