python dict更新di

2024-06-06 05:06:32 发布

您现在位置:Python中文网/ 问答频道 /正文

python是否有任何内置的功能来通知dict更新时更改了哪些dictionary元素?例如,我正在寻找这样的功能:

>>> a = {'a':'hamburger', 'b':'fries', 'c':'coke'}
>>> b = {'b':'fries', 'c':'pepsi', 'd':'ice cream'}
>>> a.diff(b)
{'c':'pepsi', 'd':'ice cream'}
>>> a.update(b)
>>> a
{'a':'hamburger', 'b':'fries', 'c':'pepsi', 'd':'ice cream'}

我想查一本字典,里面有a.diff(b)结果中显示的更改值


Tags: 功能元素dictionary字典diffupdate内置dict