I am trying to get the key values commonly present in both first_list and second_list as below,first_list and second_list has X and Z as the common keys,I want to get the values corresponding to X and Z and create a final dictionary as show in EXPECTED OUTPUT BELOW,I have the current and expected output,can someone provide guidance on what is wrong here?
first_list = [{'W':['xyz','abc','def']},{'X':['1','2','3']},{'Y':['4','5','6']},{'Z':['1','5','7']}]
second_list = [{'X':True},{'Z':True}]
first_list_keys,second_list_keys = [],[]
for item in first_list:
for key,value in item.items():
print (key,value)
first_list_keys.append(key)
for item in second_list:
for key,value in item.items():
print (key,value)
second_list_keys.append(key)
print(first_list_keys,second_list_keys)
c = set(first_list_keys).intersection(second_list_keys)
print (c)
final_dict = {}
for item in c:
item_dict = {}
for data in first_list:
for key,value in data.items():
print (key,value)
if key == item:
print ('==================')
print (value)
item_dict['deps'] = value
for item in c:
for data in second_list:
for key,value in data.items():
print (key,value)
if key == item:
print ('==================')
print (value)
item_dict['values'] = True
final_dict[key] = item_dict
print (final_dict)
CURRENT OUTPUT:-
{'Z': {'deps': ['1', '5', '7'], 'values': True}}
EXPECTED OUTPUT:-
{'X':{"deps":['1','2','3'],"values": true },'Z':{"deps":['1','5','7'],"values": true }
UPDATE:-
{'W':{"deps":['xyz','abc','def'],"values": False},'X':{"deps":['1','2','3'],"values": True },'Y':{"deps":['4','5','6'],"values":False},'Z':{"deps":['1','5','7'],"values": True }