I have a question making a dictionary with text file.
I have a text file like this:
0,1
0,2
0,3
1,2
1,3
1,4
2,3
2,4
2,5
What I am trying to do,
I would like to make {0: [1,2,3], 1:[2,3,4], 2:[3,4,5]}
like this
lists = {}
test = open('Test.txt', mode='r', encoding = 'utf-8').read().split('\n')
for i in test:
if len(lists) == 0:
lists[i.split(',')[0]] = [i.split(',')[1]]
In here, whenever I call for fuction, the value number is changed..
I am trying to figure out how I gotta do,
But it seems little bit tricky to me
Can anyone give me some advice or direction for it?
I really appreciate it
Thank you!