Python parsing in dictionary

 Not much to say, direct light Code:

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

 

Published 98 original articles · won praise 5 · views 10000 +

Guess you like

Origin blog.csdn.net/chengsilin666/article/details/84837490