ezoic

Tuesday, March 7, 2017

Python problem 4

Write a Python program to combine two dictionary adding values for common keys: 

class Solution:
    def add1(self, dic1,dic2):
        for key in dic1.keys():
            if key in dic2.keys():
                dic1[key]=dic1[key]+dic2[key]

        for key in dic2.keys():
            if key not in dic1.keys():
                dic1[key]=dic2[key]


        return(dic1)

kk=Solution()
if __name__=="__main__":
    print(kk.add1({"a":1,"k":3,"u":9},{"a":100,"u":5,"r":100}))

No comments:

Post a Comment

looking for a man

 I am a mid aged woman.  I was born in 1980. I do not have any kid. no complicated  dating before . I am looking for a man here for marriage...