Python字典没有更新

use*_*171 2 python

def mergeDict(object):
    dict1 = {}
    for i in range(len(object)):
        dict1.update({'id': object[i].id, 'name': object[i].name, 'age': object[i].age, 'location': object[i].location})
        return dict1
merged_dict = mergeDict(details_sorted)
Run Code Online (Sandbox Code Playgroud)

但这不起作用.

我想得到这样的东西:

{1: {'id': 1, 'name': 'John', 'age': '25'; 'location': 'somewhere'},
 2: {'id': 2, 'name': ......}}
Run Code Online (Sandbox Code Playgroud)

Bre*_*wey 5

看起来return语句在for循环中,这意味着它只会返回第一个dict的更新.