Python中字典的解析

 不多说,直接亮代码:

from collections import namedtuple
Book = namedtuple("Book", "author title genre")
books = [
    Book("A","B","C"),
    Book("D","E","F")
]
fantacy_authors = { b.title : b.author for b in books if b.genre=='C'}
fantacy_authors
发布了98 篇原创文章 · 获赞 5 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/chengsilin666/article/details/84837490