Convert the multidict to a plain dictionary.

        Arguments:

            flat: If True only return the a value for each key, if
                False return all values as lists.
761295
def to_dict(self, flat: bool=True) -> Dict[Any, Any]:
        
        if flat:
            return {key: value for key, value in self.items()}  # type: ignore
        else:
            return {key: self.getall(key) for key in self}
603543
def as_multi_dict(d):
    ''
    if isinstance(d, bottle.MultiDict):
        return d
    md = bottle.MultiDict()
    for k, v in d.iteritems():
        if isinstance(v, list):
            for x in v:
                md[k] = x
        else:
            md[k] = v
    return md
763186
def flatten(self):
        

        def _flatten(d):
            if isinstance(d, dict):
                for v in d.values():
                    for nested_v in _flatten(v):
                        yield nested_v
            elif isinstance(d, list):
                for list_v in d:
                    for nested_v in _flatten(list_v):
                        yield nested_v
            else:
                yield d

        return self.__class__(list(_flatten(self.items)))
775052
def queryset_to_dict(qs, key='pk', singular=True):
    
    if singular:
        result = {}
        for u in qs:
            result.setdefault(getattr(u, key), u)
    else:
        result = defaultdict(list)
        for u in qs:
            result[getattr(u, key)].append(u)
    return result
102125
def convert_dict(d, cls=AttrDict): # not used
    '''
    
    '''
    for k, v in d.items():
        if isinstance(v, Mapping):
            d[k] = convert_dict(v)
        elif isinstance(v, list):
            for i, e in enumerate(v):
                if isinstance(e, Mapping):
                    v[i] = convert_dict(e)
    return cls(d)
397329
def to_flat_dict(self, **kwargs):
        
        if kwargs:
            return self.filter(**kwargs).to_flat_dict()
        return {param.uniquetwig: param for param in self._params}
534293
def flat_model(tree):
    """"""
    names = []
    for columns in viewvalues(tree):
        for col in columns:
            if isinstance(col, dict):
                col_name = list(col)[0]
                names += [col_name + '__' + c for c in flat_model(col)]
            else:
                names.append(col)

    return names
327883
def flattened(self):
        
        flatx = {}
        flatf = {}
        for i in self.res:
            if isinstance(i, int):
                flatx[i] = []
                flatf[i] = []
                for x in sorted(self.res[i]):
                    for d in sorted(self.res[i][x]):
                        flatx[i].append(x)
                        flatf[i].append(d)
        return flatx, flatf
1329667
def clean_dict(d, test=lambda v: v):
    
    return {k: v for k, v in d.items() if test(v)}
116593
def to_dict(dictish):
    
    if hasattr(dictish, 'iterkeys'):
        m = dictish.iterkeys
    elif hasattr(dictish, 'keys'):
        m = dictish.keys
    else:
        raise ValueError(dictish)

    return dict((k, dictish[k]) for k in m())
343034
def multidict_to_dict(d):
    
    return dict((k, v[0] if len(v) == 1 else v) for k, v in iterlists(d))
1185901
def unflatten(flat_dict: Dict[str, Any]) -> Dict[str, Any]:
    
    unflat: Dict[str, Any] = {}

    for compound_key, value in flat_dict.items():
        curr_dict = unflat
        parts = compound_key.split(".")
        for key in parts[:-1]:
            curr_value = curr_dict.get(key)
            if key not in curr_dict:
                curr_dict[key] = {}
                curr_dict = curr_dict[key]
            elif isinstance(curr_value, dict):
                curr_dict = curr_value
            else:
                raise ConfigurationError("flattened dictionary is invalid")
        if not isinstance(curr_dict, dict) or parts[-1] in curr_dict:
            raise ConfigurationError("flattened dictionary is invalid")
        else:
            curr_dict[parts[-1]] = value

    return unflat
1006104
def flatten(struct):
    
    if struct is None:
        return []
    flat = []
    if isinstance(struct, dict):
        for key, result in struct.items():
            flat += flatten(result)
        return flat

    if isinstance(struct, basestring):
        return [struct]

    try:
        # if iterable
        for result in struct:
            flat += flatten(result)
        return flat
    except TypeError:
        pass

    return [struct]
1158394
def _convert(self, val):
        
        if isinstance(val, dict) and not isinstance(val, DotDict):
            return DotDict(val), True
        elif isinstance(val, list) and not isinstance(val, DotList):
            return DotList(val), True

        return val, False
216469
def dict_to_form(dict):
    '''
    
    '''
    from flatland import Boolean, Form, String, Integer, Float

    def is_float(v):
        try:
            return (float(str(v)), True)[1]
        except (ValueError, TypeError):
            return False

    def is_int(v):
        try:
            return (int(str(v)), True)[1]
        except (ValueError, TypeError):
            return False

    def is_bool(v):
        return v in (True, False)

    schema_entries = []
    for k, v in dict.iteritems():
        if is_int(v):
            schema_entries.append(Integer.named(k).using(default=v,
                                                         optional=True))
        elif is_float(v):
            schema_entries.append(Float.named(k).using(default=v,
                                                       optional=True))
        elif is_bool(v):
            schema_entries.append(Boolean.named(k).using(default=v,
                                                         optional=True))
        elif type(v) == str:
            schema_entries.append(String.named(k).using(default=v,
                                                        optional=True))

    return Form.of(*schema_entries)
131824
def to_dict(item):
        
        def convert(item):
            if isinstance(item, IterableObject):
                if isinstance(item.source, dict):
                    return {k: convert(v.source) if hasattr(v, 'source') else convert(v) for k, v in item}
                else:
                    return convert(item.source)
            elif isinstance(item, dict):
                return {k: convert(v) for k, v in item.items()}
            elif isinstance(item, list):
                def yield_convert(item):
                    for index, value in enumerate(item):
                        yield convert(value)
                return list(yield_convert(item))
            else:
                return item

        return convert(item)
738005
def _flatten_ex_dict(self):
        """"""
        odict = {}
        for _, fdict in self._ex_dict.items():
            for (extype, exmsg), value in fdict.items():
                key = value["name"]
                odict[key] = copy.deepcopy(value)
                del odict[key]["name"]
                odict[key]["type"] = extype
                odict[key]["msg"] = exmsg
        return odict