File:
1 2,5 3,1
2 4,10 1,5
3 4,1 1,1
4 2,10 3,1
I'd like to create dictionary as follows:
{1:[[2,5], [3,1]], 2:[[4,10], [1,5]],
3: [[4,1], [1,1]], 4: [[2,10], [3,1]]}
I managed to achieve this:
{1: [['2,5'], ['3,1']], 2: [['4,10'], ['1,5']],
3: [['4,1'], ['1,1']], 4: [['2,10'], ['3,1']]}
Using the following code:
f = open("file.txt")
D = {}
for line in f:
line = line.strip().split(" ")
for i in line:
D[int(line[0])] = [[x] for x in line[1:]]
print D
[x]you want something likemap(int, x.split(','))?