【发布时间】:2019-05-12 18:05:38
【问题描述】:
所以我有这个字典列表:
[{u'id': u'53532', u'name': u'IMG_1.jpg'},
{u'id': u'53533', u'name': u'IMG_2.jpg'},
{u'id': u'53534', u'name': u'IMG_3.jpg'}]
还有这个元组列表:
[(53532, image ,'https://sample.jpg'),
(53533, image ,'https://sample.jpg'),
(53534, image ,'https://sample.jpg')
]
如何将字典的 id 值与元组中的值匹配,如果它们匹配,则将元组添加到匹配的字典中的新键:
例如,如果它们匹配看起来像这样:
{u'id': u'53532',
u'name': u'IMG_1.jpg',
u'img_attr':(53532, image ,'https://sample.jpg')
}
【问题讨论】:
-
OP 提到它是 Python2.7 -> 添加标签
标签: python python-2.7 list dictionary tuples