Q. Given two dictionaries say d1 and d2
Write a program that lists the over lapping keys of the two dictionaries if a key of d1 is also a key of d2, the list it.
You can understand by Watching video :-
Answer :-
d1 = eval(input("Enter first dictionary = ")) d2 = eval(input("Enter second dictionary = ")) lst1 = (d1.keys() ) lst2 = (d2.keys() ) lst = [ ] for i in lst1 : for j in lst2 : if i == j : lst += [ i ] print("Over lapping keys are ",lst )
Output :-
Enter first dictionary = {"Path":9,"Walla":15,"Portal":41,"Express":5}
Enter second dictionary = {"Python":8,"Path":0,"C++":2,"Java":78,"Portal":48}
Over lapping keys are ['Path', 'Portal']
>>>
Enter first dictionary = {"Path":9,"Walla":15,"Portal":41,"Express":5}
Enter second dictionary = {1:8,5:7,"Path":4}
Over lapping keys are ['Path']
>>>
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )