Python dictionary having tuple keys and values
Question: What I like to have is a dictionary in the format of
`{(x1,y1):(a1,b1,c1),(x2,y2):(a2,b2,c2),(x3,y3):(a3,b3,c3),...}`

All the data is in a text file in a format like this:

    
    
    x1 y1 a1
    ...
    x1 y1 b1
    ...
    x1 y1 c1
    ...
    x2 y2 a2
    ...
    x2 y2 b2
    ...
    x2 y2 c2 
    ...
    

I read the text file but I don't know how to associate the a, b, c values with
the corresponding key.

The script I have right now gives me `{(x1,y1):c1,(x2,y2):c2,(x3,y3):c3,...}`
which is not correct

Since I read the lines one by one, I am not sure how I can save the a , b
values.


Answer: 
    with open('path/to/input') as infile:
        answer = {}
        for line in infile:
            x,y,v = line.split()
            k = (x,y)
            if k not in answer:
                answer[k] = []
            answer[k].append(v)
    answer = {k:tuple(v) for k,v in answer.items()}
    

Of course, you could use `collections.defaultdict` to ease your burden just a
little:

    
    
    import collections
    with open('path/to/input') as infile:
        answer = collections.defaultdict(list)
        for line in infile:
            x,y,v = line.split()
            answer[(x,y)].append(v)
    answer = {k:tuple(v) for k,v in answer.items()}
    

