(ordered_pairs)
return dict(d)
Convert duplicate keys values to lists.
Convert duplicate keys values to lists.
Convert duplicate keys values to lists .
def multidict(ordered_pairs):
    """Convert duplicate keys values to lists."""
    # 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
    dict_copy = deepcopy(d)
    for k, v in iteritems(dict_copy):
        if len(v) == 1:
            d[k] = v[0]
    return dict(d)
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 dict_copy = deepcopy ( d ) for k , v in iteritems ( dict_copy ) : if len ( v ) == 1 : d [ k ] = v [ 0 ] return dict ( d )