【发布时间】:2020-05-03 11:01:13
【问题描述】:
我有一个字典列表,我想为每个字典做一个以找到相应的值。
我的清单:
my_list = [{'genre':'Dystopia', 'book':'Hunger Games'},
{'genre':'Fanstasy', 'book':'Harry Potter'},
{'genre':'Dystopia', 'book':'Divergent'}]
我想获得与该类型相对应的书籍。
预期结果:
for 'Dystopia' get 'Hunger Games', 'Divergent'
for 'Fantasy' get 'Harry Potter'
我不知道该怎么做。我知道我需要一个 for 循环,但不知道除此之外还能做什么。
for x in my_list:
x['url']
不确定接下来要添加什么。
【问题讨论】:
-
到底是什么问题?那个 for 循环对我来说看起来不错。你为什么要为此使用字典列表?
标签: python python-3.x dictionary for-loop arraylist