I have 2 dictionaries and one of them is nested. I would like to create another nested dictionary by checking keys and values of these two dictionaries. 'dict1' gives the connections between the key and the elements of the list:

dict1={'A': ['K', 'J'], 'C': ['A'], 'D': ['B', 'C']}

dict2 has same keys (less or more) compared to dict1 as:

dict2={'D': {'D': '0.20','B': '0.20','C': '0.00','A': '0.06','K': '0.00','J': '0.02'},'A':{'K':'3','J':'3'}}

For a given key in the first level and all the other keys in the second level of dict2, I would like to create a nested dictionary which checks dict1 and its list to see the connections. If an element from the list of dict1 (which matches with second level of the nested dict2) has zero value in dict2, it should checks its list connection in dict1, and do the connection with dict1 elements until it reaches to non-zero value. For instance, 'D' in dict1 has list of ['B','C']. 'B':0.20 which is non-zero in dict2 so we can do connection as ('D','B',[]). Then, we check for 'D' and 'C'. Given 'D' and 'C':'0.00', we check dict1 for 'C' and see that it has list of ['A'] which is non-zero in dict2 ('A': '0.06') so we get ('D','A',[C]). If 'A' was zero in dict2 then we should have checked dict1 to see that 'A': [['K', 'J'] then check whether 'K' and 'J' are non-zero. If they were non-zero then we should have gotten (D,K,[]) and (D,J,[]). Given these, I would like to obtain a nested dictionaries like below so that I can have the connections and list of keys which are like intermediary within my connections:

result={'D': {('D','B',[]),('D','A',['C']),('A','J',[])}'A':{('A','K',[]),('A','J',[])}}

'result' should give me the connections and also the list that shows if I have had any element between the connected ones while creating the connections. This is how far I could get but I cant get my intended output whereas I have bigger data unlike the example here:

**What I have tried:**
output = []
for target in dict2:
for key in dict1:
for i in dict1[key]:
if dict2[target][i]!='0.00':
output.append((key, i))

thanks