将一个字典的嵌套列表附加到另一个字典的嵌套列表?

Append nested list from one dictionary to a nested list of another dictionary?

我有 2 部词典:

a = {'name': 'Bob', 'values': ['abcd']}
b = {'name': 'Jack', 'values': ['efg']}

期望的输出:

b = {'name': 'Jack', 'values': ['abcd','efg']}

当前代码:(不需要的输出)

b['values'].append(a['values'])

print(b)
>>>{'name': 'Jack', 'values': ['abcd', ['efg']]}

不要追加,您应该添加元素:

b['values']+=a['values']

您也可以尝试 listsextend 方法,例如:

b['values'].extend(a['values'])

>>> b
{'name': 'Jack', 'values': ['efg', 'abcd']}