2016-03-05 72 views
0

我有一個像字典如下:Python字典子元素列出

d = {"result": {"page": "1", "games": {"game": {"id": "2016", "name": "Exemple"}}}} 

我想組d['result']['games']['game']所有子值的列表,如:

d = {"result": {"page": "1", "games": {"game": [{"id": "2016", "name": "Exemple"}]}}} 

我怎樣才能做這個編程,修改我的字典變量?

回答

0

d['result']['games']['game'] = [d['result']['games']['game']]

,如果你想添加其他元素

d['result']['games']['game'].append({some other dict})

+0

謝謝你,它的工作原理:) – zipuniz1999