if (H[node1])[node2] != 1:
Your graph representation doesn't represent missing links with a non-1 value. It represents that a link is missing by not including the relevant dict entries at all. Iterate over all nodes instead of just the ones that have links, and check whether node2
is a key in H[node1]
:
for node1 in H:
for node2 in H:
if node2 not in H[node1]:
make_link(I, node1, node2)