我想創建持有多維值的Python字典接受,它應該是能夠擴大,這是值應存儲結構: -Python |如何創建動態的,可擴展的字典
userdata = {'data':[{'username':'Ronny Leech','age':'22','country':'Siberia'},{'username':'Cronulla James','age':'34','country':'USA'}]}
比方說,我想添加其他用戶
def user_list():
users = []
for i in xrange(5, 0, -1):
lonlatuser.append(('username','%s %s' % firstn, lastn))
lonlatuser.append(('age',age))
lonlatuser.append(('country',country))
return dict(user)
這隻會返回與一個單一值的字典(因爲這些按鍵的名稱是相同的值將覆蓋)。所以我怎麼一組值追加到此字典。
注意:假設年齡,firstn,lastn和country是動態生成的。
謝謝。
lontatuser與列表中的用戶數據關鍵數據?你輸入字典的用戶是什麼? – extraneon 2010-03-18 08:32:05