早教吧 育儿知识 作业答案 考试题库 百科 知识分享

python英文题目求解答!~~~~Givendictionaries,d1andd2,createanewdictionarywiththefollowingproperty:foreachentry(a,b)ind1,ifaisnotakeyofd2(i.e.,notaind2)thenadd(a,b)tothenewdictionaryforeachentry(a,b)in

题目详情
python英文题目求解答!~~~~
Given dictionaries, d1 and d2, create a new dictionary with the following property: for each entry (a, b) in d1, if a is not a key of d2 (i.e., not a in d2) then add (a,b) to the new dictionary for each entry (a, b) in d2, if a is not a key of d1 (i.e., not a in d1) then add (a,b) to the new dictionary
For example, if d1 is {2:3, 8:19, 6:4, 5:12} and d2 is {2:5, 4:3, 3:9}, then the new dictionary should be {8:19, 6:4, 5:12, 4:3, 3:9}
Associate the new dictionary with the variable d3
▼优质解答
答案和解析
def new_dict(dict1, dict2): newdict = {} newdict.update(dict1) newdict.update(dict2) d = newdict.copy() for i in d.iterkeys(): if dict1.has_key(i) and dict2.has_key(i): ...