2016-11-30 53 views
0

僞代碼:Python的 - 如何更新列表indicies

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

在這裏,我做了一些計算,我想更新數據[0],爲了得到:

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

我怎樣才能更新列表的第一個索引?

+0

'data.insert(0,{ '名': '約翰', '年齡':'37, '國家': 'USA' })'? –

+0

你有什麼問題? –

+0

你有什麼問題? – Barry

回答

6

像:

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

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