python练习:匹配获取对应的值

# 将photos中的userid为1的该条数据的photoname的值
# 赋值给users中的userid为1的该条数据的photoname的值
users = [{'userid': 1, 'photoname': None,'name':'zyh'},{'userid': 2, 'photoname': None,'name':'zyh'}]
photos=[{'userid':1,'photoname':'1.png'}]

a = {}
for p in photos:
a[p['userid']]=p['photoname']
for u in users:
if u['userid'] in a.keys():
u['photoname']=u['userid']

print(users)
posted @ 2020-04-06 00:34  红红乐园  阅读(753)  评论(0编辑  收藏  举报