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)