ezoic

Wednesday, March 8, 2017

Python problem 6

Write a Python program to match key values in two dictionaries

Sample dictionary: {'key1': 1, 'key2': 3, 'key3': 2}, {'key1': 1, 'key2': 2}
Expected output: key1: 1 is present in both x and y

class Solution:
    def two1(self, dic1,dic2):
        dic3={}
        for key in dic1.keys():
            if key in dic2.keys() and dic1[key]==dic2[key]:
                dic3[key]=dic1[key]
        return(dic3)


kk=Solution()
if __name__=="__main__":

    print(kk.two1({"a":1,"b":5,"i":9,"o":3},{"a":1,"b":5,"o":3,"t":19,"u":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...