我该如何查找值为
user7
的dictionary
,然后更新它的match_sum
,例如在现有值4的基础上加3。l = [{'user': 'user6', 'match_sum': 8},
{'user': 'user7', 'match_sum': 4},
{'user': 'user9', 'match_sum': 7},
{'user': 'user8', 'match_sum': 2}
]
我有这个,但不确定这是否是最佳实践。
>>> for x in l:
... if x['user']=='user7':
... x['match_sum'] +=3