[ create a new paste ] login | about

Link: http://codepad.org/xOOrlbnf    [ raw code | output | fork ]

Python, pasted on Feb 12:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class MultiMap(object):
    values = {}
    
    def __getitem__(self, index):
        return self.values[index]
    def __setitem__(self, index, value):
        if not self.values.has_key(index):
            self.values[index] = []
        self.values[index].append(value)
    def __repr__(self):
        return repr(self.values)

a = MultiMap()
a[1] = 2
a[2] = 3
a[1] = 4

print a


Output:
1
{1: [2, 4], 2: [3]}


Create a new paste based on this one


Comments: