Returns a dictionary excluding keys from a source dictionary.

  :source: a dictionary
  :keys: a set of keys, or a predicate function that accepting a key
  :transform: a function that transforms the values
184955
def exclude(source, keys, *, transform=None):
  
  check = keys if callable(keys) else lambda key: key in keys
  return {key: transform(source[key]) if transform else source[key]
          for key in source if not check(key)}
792437
def _filter(self, dict, keep):
        
        if not keep:
            return dict

        result = {}
        for key, value in dict.iteritems():
            if key in keep:
                result[key] = value
        return result
1110358
def _dict_subset(keys, master_dict):
    '''
    
    '''
    return dict([(k, v) for k, v in six.iteritems(master_dict) if k in keys])
919107
def clean_dict_keys(d):
    
    new_d = {}
    for (k, v) in d.iteritems():
        new_d[str(k)] = v
    return new_d
451475
def full_dict(ldict, keys):
    
    if type(keys) == str:
        keys = [keys]
    else:
        keys = keys

    cmp_dict = {}
    for line in ldict:
        index = []
        for key in keys:
            index.append(str(line.get(key, '')))
        index = '-'.join(index)
        cmp_dict[index] = line

    return cmp_dict
115162
def keyfilter(predicate, d, factory=dict):
    
    rv = factory()
    for k, v in iteritems(d):
        if predicate(k):
            rv[k] = v
    return rv
1258616
def exclude_keys(self,key_list):
        
        if isinstance(key_list,basestring):
            key_list = key_list.split(',')
        return type(self)([ (k,self[k]) for k in self if k not in key_list ])
614254
def str2dict_keys(str_in):
    '''
    
    '''
    tmp_dict = str2dict(str_in)
    if tmp_dict is None:
        return None
    return sorted([k for k in tmp_dict])
1269583
def getdict(source):
    
    std_dict = {}
    for var, val in source.iteritems():
        std_dict[var] = source[var]
    return std_dict
706548
def to_dict(self, remove_nones=False):
        

        if remove_nones:
            return {k: v for k, v in self.to_dict().items() if v is not None}
        else:
            raise NotImplementedError()
139817
def valid_dict(d, keys=None):
    

    if keys is None:
        d_ = d
    else:
        d_ = itemfilter(lambda item: item[0] in keys, d)
        if len(d_) != len(keys):
            return False
    values = list(itervalues(d_))
    return False if None in values else True
21486
def remove(self, key):
        ''''''
        copydict = ImmutableDict()
        copydict.tree = self.tree.remove(hash(key))
        copydict._length = self._length - 1
        return copydict
1219704
def dict(
        self, *, include: 'SetStr' = None, exclude: 'SetStr' = None, by_alias: bool = False, skip_defaults: bool = False
    ) -> 'DictStrAny':
        
        get_key = self._get_key_factory(by_alias)
        get_key = partial(get_key, self.fields)

        return_keys = self._calculate_keys(include=include, exclude=exclude, skip_defaults=skip_defaults)
        if return_keys is None:
            return {get_key(k): v for k, v in self._iter(by_alias=by_alias, skip_defaults=skip_defaults)}
        else:
            return {
                get_key(k): v for k, v in self._iter(by_alias=by_alias, skip_defaults=skip_defaults) if k in return_keys
            }
282146
def _get_keys_defdict(self):
        '''
        '''
        # inspect argspecs
        argspec = inspect.getargspec(self.func)
        keys, defvals = argspec.args, argspec.defaults

        # convert to (list_of_argkeys, dict_of_default_keys)
        if defvals is None:
            return keys, None
        else:
            defvals = list(defvals)
            keys.reverse()
            defvals.reverse()
            defdict = dict(zip(keys, defvals))
            keys.reverse()
            return keys, defdict
415676
def get_filtered_keys(self, suffix, *args, **kwargs):
        

        args = self.prepare_args(args, transform=False)

        for index in self._indexes:
            if index.can_handle_suffix(suffix):
                return index.get_filtered_keys(suffix, *args, **kwargs)
334070
def get(self, keys, default=None):
        
        try:
            d = self
            for k in keys.split("."):
                if not k in d:
                    d[k] = {}
                d = d[k]
            if isinstance(d, bool):
                return d
            return d or default
        except (TypeError, KeyError) as e:
            return default
959449
def dict(self):
        
        from collections import OrderedDict
        SKIP_KEYS = ()
        return OrderedDict(
            (p.key, getattr(self, p.key)) for p in self.__mapper__.attrs if p.key not in SKIP_KEYS)