def merge_dict(dict_li, attr_li, missingvalue=None):
    """
    Merging multiple dictionaries into a new one.
    Example:
    In [136]: d1 = {'id1': 100, 'id2': 200}
    In [137]: d2 = {'id1': 'aaa', 'id2': 'bbb', 'id3': 'ccc'}
    In [138]: merge_dict([d1,d2], ['number', 'string'])
    Out[138]:
    {'id1': {'number': 100, 'string': 'aaa'},
     'id2': {'number': 200, 'string': 'bbb'},
     'id3': {'string': 'ccc'}}
    In [139]: merge_dict([d1,d2], ['number', 'string'], missingvalue='NA')
    Out[139]:
    {'id1': {'number': 100, 'string': 'aaa'},
     'id2': {'number': 200, 'string': 'bbb'},
     'id3': {'number': 'NA', 'string': 'ccc'}}
    """
    dd = dict(zip(attr_li, dict_li))
    key_set = set()
    for attr in dd:
        key_set = key_set | set(dd[attr])
    out_dict = {}
    for k in key_set:
        value = {}
        for attr in dd:
            if k in dd[attr]:
                value[attr] = dd[attr][k]
            elif missingvalue is not None:
                value[attr] = missingvalue
        out_dict[k] = value
    return out_dict
