小编Abh*_*han的帖子

想以排序方式查看字典合并

我能够合并两个字典,但想与dict1一起继续看dict 2

def Merge(dict1, dict2):
    res={**dict1, **dict2}

    return res

dict1= {'a':3,'b':7,'c':9}
dict2= {'d':7,'e':8}
mergedict = Merge(dict1,dict2)

print(mergedict)
Run Code Online (Sandbox Code Playgroud)

实际结果{'d': 7, 'a': 3, 'e': 8, 'b': 7, 'c': 9}

预期结果{'a':3, 'b':7, 'c':9, 'd':7, 'e':8}

python python-3.x

1
推荐指数
1
解决办法
69
查看次数

标签 统计

python ×1

python-3.x ×1