Gets 2nd-level data into 1st-level dictionary

    :param dictionary: dict
    :return: with 2nd-level data
174503
def get_inner_data(dictionary):
    

    out = {}

    for key in dictionary.keys():
        inner_keys = dictionary[key].keys()
        for inner_key in inner_keys:
            new_key = key + " " + inner_key  # concatenate
            out[new_key] = dictionary[key][inner_key]

    return out
1160174
def to_dict(self):
        """"""
        return {
            'level': self.level,
            'id': self.id,
            'text': self.text,
            'inner_html': self.inner_html,
            'children': [child.to_dict() for child in self.children]
        }
128178
def struct2dict(struct):
    """"""
    return {x: getattr(struct, x) for x in dict(struct._fields_).keys()}
527152
def str2dict(str_in):
    '''
    
    '''
    dict_out = safe_eval(str_in)
    if not isinstance(dict_out, dict):
        dict_out = None
    return dict_out
481574
def _perm_dict_from_subj_dict(self, subj_dict):
        """"""
        perm_dict = {}
        for subj_str, perm_set in list(subj_dict.items()):
            for perm_str in perm_set:
                perm_dict.setdefault(perm_str, set()).add(subj_str)
        return perm_dict
232435
def _get_val2_dict_from_diff_dict(diff_dict):
    '''
    
    '''
    ret_dict = {}
    for p in diff_dict.keys():
        if not isinstance(diff_dict[p], dict):
            raise ValueError('Unexpected diff difct \'{0}\''.format(diff_dict))
        if 'val2' in diff_dict[p].keys():
            ret_dict.update({p: diff_dict[p]['val2']})
        else:
            ret_dict.update(
                {p: _get_val2_dict_from_diff_dict(diff_dict[p])})
    return ret_dict
1087529
def _get_key_data(d, key):
    
    d2 = ""
    try:
        d2 = d[key]
    except KeyError:
        logger_dataframes.info("get_key_data: KeyError: {}".format(key))
    return d2
1042413
def get_data(model, instance_id, kind=''):
    
    instance = get_instance(model, instance_id)

    if not instance:
        return

    return ins2dict(instance, kind)
980008
def deep_merge(dict_one, dict_two):
    '''
    
    '''
    merged = dict_one.copy()
    for key, value in dict_two.items():
        # value is equivalent to dict_two[key]
        if (key in dict_one and
                isinstance(dict_one[key], dict) and
                isinstance(value, dict)):
            merged[key] = deep_merge(dict_one[key], value)
        elif (key in dict_one and
              isinstance(dict_one[key], list) and
              isinstance(value, list)):
            merged[key] = list(set(dict_one[key] + value))
        else:
            merged[key] = value
    return merged
572337
def _build_dictionary(self, results):
        
        foreign = self._first_key

        dictionary = {}

        for result in results:
            key = getattr(result, foreign)
            if key not in dictionary:
                dictionary[key] = []

            dictionary[key].append(result)

        return dictionary
187369
def _get_diffs(cls, dict1, dict2, ignore_missing_keys):
        '''
        
        '''
        ret_dict = {}
        for p in dict1.keys():
            if p not in dict2:
                ret_dict.update({p: {'new': dict1[p], 'old': cls.NONE_VALUE}})
            elif dict1[p] != dict2[p]:
                if isinstance(dict1[p], dict) and isinstance(dict2[p], dict):
                    sub_diff_dict = cls._get_diffs(dict1[p], dict2[p],
                                                   ignore_missing_keys)
                    if sub_diff_dict:
                        ret_dict.update({p: sub_diff_dict})
                else:
                    ret_dict.update({p: {'new': dict1[p], 'old': dict2[p]}})
        if not ignore_missing_keys:
            for p in dict2.keys():
                if p not in dict1.keys():
                    ret_dict.update({p: {'new': cls.NONE_VALUE,
                                         'old': dict2[p]}})
        return ret_dict
1003780
def _from_dict(cls, _dict):
        """"""
        args = {}
        if 'location' in _dict:
            args['location'] = Location._from_dict(_dict.get('location'))
        if 'text' in _dict:
            args['text'] = _dict.get('text')
        if 'section_title' in _dict:
            args['section_title'] = SectionTitle._from_dict(
                _dict.get('section_title'))
        if 'table_headers' in _dict:
            args['table_headers'] = [
                TableHeaders._from_dict(x) for x in (_dict.get('table_headers'))
            ]
        if 'row_headers' in _dict:
            args['row_headers'] = [
                RowHeaders._from_dict(x) for x in (_dict.get('row_headers'))
            ]
        if 'column_headers' in _dict:
            args['column_headers'] = [
                ColumnHeaders._from_dict(x)
                for x in (_dict.get('column_headers'))
            ]
        if 'key_value_pairs' in _dict:
            args['key_value_pairs'] = [
                KeyValuePair._from_dict(x)
                for x in (_dict.get('key_value_pairs'))
            ]
        if 'body_cells' in _dict:
            args['body_cells'] = [
                BodyCells._from_dict(x) for x in (_dict.get('body_cells'))
            ]
        return cls(**args)
314363
def _encode_dict(self, obj):
        """"""

        self._increment_nested_level()

        buffer = []
        for key in obj:
            buffer.append(self._encode_key(key) + ':' + self._encode(obj[key]))

        self._decrement_nested_level()

        return '{'+ ','.join(buffer) + '}'
609708
def _dict_compose(dict1, dict2):
    
    return {k: dict2.get(v) for k, v in dict1.items() if v in dict2}
1364612
def get_dict(cls):
        
        mdt = cls.get()

        if not mdt:
            return {}

        return conspectus.subs_by_mdt.get(mdt, {})
75976
def to_dict(self):
        

        return {
            'current': self.current,
            'first': self.first,
            'last': self.last,
            'next': self.more,
            'prev': self.prev,
        }
1303869
def dict2obj(d):
    
    if isinstance(d, (list, tuple)):
        d = [dict2obj(x) for x in d]
    if not isinstance(d, dict):
        return d
    class ObjectFromDict(object):
        pass
    o = ObjectFromDict() #an object created from a dict
    for k in d:
        o.__dict__[k] = dict2obj(d[k])
    return o