def items_to_dict(items):
 res = collections.defaultdict(list)
 for (k, v) in items:
  res[k].append(v)
 return normalize_dict(dict(res))

def items_to_dict ( items ) : res = collections . defaultdict ( list ) for ( k , v ) in items : res [ k ] . append ( v ) return normalize_dict ( dict ( res ) )
converts list of tuples to dictionary with duplicate keys converted to lists .