Answer:
1
def dict_intersect(d1,d2): #create dictionary
d3={} #dictionaries
for key1,value1 in d1.items(): #iterate through the loop
if key1 in d2: #checking condition
d3[key1]=(d1[key1],d2[key1]) #add the items into the dictionary
return d
3
print(dict_intersect({'a': 'apple', 'b': 'banana'}, {'b': 'bee', 'c': 'cat'})) #display
2
def consolidate(*l1): #create consolidate
d3={} #
create dictionary
for k in l1: #iterate through the loop
for number in k: #iterate through the loop d3[number]=d3.get(number,0)+1 #increment the value
return d
3 #return
print(consolidate([1,2,3], [1,1,1], [2,4], [1])) #display
Explanation:
1
Following are the description of program
- Create a dictionary i.e"dict_intersect(d1,d2) " in this dictionary created a dictionary d3 .
- After that iterated the loop and check the condition .
- If the condition is true then add the items into the dictionary and return the dictionary d3 .
- Finally print them that are specified in the given question .
2
Following are the description of program
- Create a dictionary consolidate inside that created a dictionary "d3" .
- After that iterated the loop outer as well as inner loop and increment the value of items .
- Return the d3 dictionary and print the dictionary as specified in the given question .