All pastes #294337 Raw Edit

Someone

public python v1 · immutable
#294337 ·published 2006-12-28 11:15 UTC
rendered paste body
class listdict(dict):    """    >>> listdict({"un": 1, "deux": 2})    {'un': [1], 'deux': [2]}    >>> listdict(un=1, deux=2)    {'un': [1], 'deux': [2]}    """    def __init__(self, *args, **kw):        dict.__init__(self)        if args:            kw = args[0]        for (k, v) in kw.iteritems():            if type(v) == list:                continue            elif type(v) == tuple:                dict.__setitem__(self, k, list(v))            else:                dict.__setitem__(self, k, [v,])    def __setitem__(self, key, value):        try:            self[key].append(value)        except KeyError:            dict.__setitem__(self, cle, [valeur,])if __name__ == "__main__":    import doctest    print "Test module"    doctest.testmod()