I am trying to find all the keys that include the corresponding values using the following code, I have the current output and expected output,can someone provide guidance on what I am doing wrong?
CODE:-
info = [
{'x':['y','z']},
{'a':['y','x']},
{'p':['q','z']},
{'z':['x','q']}
]
output_list = []
for d in info:
for key,value in d.items():
print (key,value)
new_list,new_dict = [],{}
for element in value:
print (element)
new_list.append(key)
new_dict[key] = new_dict
output_list.append(new_list)
print (output_list)
CURRENT OUTPUT:-
[['x', 'x'], ['x', 'x'], ['a', 'a'], ['a', 'a'], ['p', 'p'], ['p', 'p'], ['z', 'z'], ['z', 'z']]
EXPECTED OUTPUT:
[
{'y':['x','a']},
{'z' = ['x','p']},
{'x' = ['a','z']},
{'q' = ['p','z']}
]