I have a file in which there are 2 names on each line. Let's say i have the following input:
name1 name2
name3 name4
name1 name5
I want to make a dictionary like this:
name1 : [name2, name5]
name2 : name1
name3 : name4
name4 : name3
name5 : name1
Here is the code I made but i can't figure out what i did wrong..
d = {}
for i in range(len(l)): # consider l the input
d[l[i]] = ""
for i in range(0, len(l), 2):
e1 = l[i]
e2 = l[i+1]
d.update({e1 : [d[e1], e2]}) #i think the update operation is wrong here..
d.update({e2 : [d[e2], e1]})
print(l)at the beginning.