简体   繁体   English

Python-如何更新列表索引

[英]Python - how to update list indicies

Pseudo code: 伪代码:

data = []
data.append({'name': 'John', 'age': '37'})
data.append({'name': 'Joe', 'age': '25'})

Here I do some calculations and I want to update data[0], in order to get: 在这里,我做了一些计算,我想更新数据[0],以获得:

data[0] = {'name': 'John', 'age': '37', 'country': 'USA'}

How can I update that first index of list? 如何更新列表的第一个索引?

Like: 喜欢:

data[0]['country'] = 'USA' # if you want to set value of country only

or 要么

data[0] = {'name': 'John', 'age': '37', 'country': 'USA'} # if you want to update whole dictionary 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM