Im trying to make a graph edge list from a dictionary in python, with the following code:
graph= []
for key, value in dic_test.items():
for x in range (0,len(value)):
if (x+1) < len(value):
for y in range (1,len(value)):
if y != x and y>x:
graph.append([value[x],value[y]])
This gets what I want, for example if I get this test dictionary:
dic_test= {1: ['A', 'E','F','G'], 2: ['B', 'D','X'], 3: ['C',"Y"],4:[],5:['f','h']}
I get the following output:
[['A', 'E'],
['A', 'F'],
['A', 'G'],
['E', 'F'],
['E', 'G'],
['F', 'G'],
['B', 'D'],
['B', 'X'],
['D', 'X'],
['C', 'Y'],
['f', 'h']]
Problem is when I run a big dictionary it runs until the kernel crashes, any ideas I could make this code more efficient?