def multidict(ordered_pairs):
    # read all values into lists
    d = defaultdict(list)
    for k, v in ordered_pairs:
        d[k].append(v)
    # unpack lists that have only 1 item
    for k, v in d.items():
        if len(v) == 1:
            d[k] = v[0]
    return dict(d)
Convert duplicate keys values to lists.
dataset/ETHPy150Open serverdensity/sd-agent/checks.d/riakcs.py/multidict