作业帮 > 综合 > 作业

python字典中的键和值的替换操作,需要写一个function,就叫sub(dict1,dict2),以下是例子,

来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/17 18:06:26
python字典中的键和值的替换操作,需要写一个function,就叫sub(dict1,dict2),以下是例子,
整个题的大概意思就是如果dict2里面的变量名字和dict1一样,那就直接把dict1对应变量的值换到dict2中的位置里.
我觉得应该就是将两个字典都循环一遍来对比,但是就是在判断上很难写的准确,总是有bug,
dict1 = {"x":{"Number":[5]}}
dict2 = {"Variable":['x']}
return dict3 = {"Number":[5]}
dict1 = {"y":{"Number":[2]}}
dict2 = {"Plus":[{"Variable":['y']},{"Variable":['y']}]}
return dict3 = {"Plus":[{"Number":[2]},{"Number":[2]}]}
dict1 = {"a":{"Number":[1]},"b":{"Number":[2]}}
dict2 = {"Mult":[{"Variable":['y']},{"Variable":['y']}]}]
return dict3 = {"Mult":[{"Variable":['y']},{"Variable":['y']}]}
dict1 = {"a":{"Number":[1]},"b":{"Number":[2]}}
dict2 = {"Mult":[{"Plus":[{"Variable":['y']},{"Variable":['y']}]},{"Variable":['b']}]}]
return dict3 = {"Mult":[{"Plus":[{"Variable":['y']},{"Variable":['y']}]},{"Number":[2]}]}
dict1 = {"z":{"Number":[2]}}
dict2 = {"Plus":[{"Variable":['y']},{"Variable":['z']}]}]
return dict3 = {"Plus":[{"Variable":['y']},{"Number":[2]}]}
python字典中的键和值的替换操作,需要写一个function,就叫sub(dict1,dict2),以下是例子,
房价也还没计划叶锦添