def  defaultdict_example():
    ''' show some examples for defaultdicts '''
    pairs = {('a', 1), ('b',2), ('c',3)}

    d1 = {}
    for key, value in pairs:
        if key not in d1:
            d1[key] = []
        d1[key].append(value)
    print(d1)

    d2 = defaultdict(list)
    for key, value in pairs:
        d2[key].append(value)
    print(d2)
dataset/ETHPy150Open bt3gl/Python-and-Algorithms-and-Data-Structures/src/USEFUL/basic_examples/example_defaultdict.py/defaultdict_example/original