I have a dictionary with lists as values and strings as keys. The values are build like this (4, 7) and at least one of both numbers will be in the values from the following key.
The dictionary looks like this:
dot_z =
{
'1': [[4, 7], [7, 8], [7, 9], [6, 7]],
'2': [[4, 5], [8, 10], [3, 4]],
'3': [[1, 3], [2, 3], [3, 11]],
'4': [[11, 12], [11, 13], [2, 15]]
'5': [[15, 16], [12, 14]]
}
My goal is to receive a new dictionary that should look like this:
7: [4, 8, 9, 6],
4: [5, 3],
8: [10],
9: [],
6: [],
10: [],
5: [],
3: [1, 2, 11],
1: [],
2: [15],
11: [12, 13],
15: [16],
12: [14],
13: []
That means that dict first line number 7 gets removed because it is connected to all of them. Next step is to take all numbers that are connected to 7 and to check to which number they are connected. In the end each number represents a dot that is connected to another number/dot. In the new dictionary the keys represent the starting numbers and their values will contain all numbers that they are connected to.
How is it possible to achieve this?