simple method for assigning or setting values with a similar interface
    to dict_take
495792
def dict_assign(dict_, keys, vals):
    
    for key, val in zip(keys, vals):
        dict_[key] = val
699096
def add_to_obj(obj, dictionary, objs=None, exceptions=None, verbose=0):
    
    if exceptions is None:
        exceptions = []
    for item in dictionary:
        if item in exceptions:
            continue
        if dictionary[item] is not None:
            if verbose:
                print("process: ", item, dictionary[item])
            key, value = get_key_value(dictionary[item], objs, key=item)
            if verbose:
                print("assign: ", key, value)
            try:
                setattr(obj, key, value)
            except AttributeError:
                raise AttributeError("Can't set {0}={1} on object: {2}".format(key, value, obj))
1141117
def dict_values(src):
    
    for v in src.values():
        if isinstance(v, dict):
            for v in dict_values(v):
                yield v
        else:
            yield v
1007225
def _set_fields(self, json_dict):
        
        for key, value in json_dict.items():
            if not key.startswith("_"):
                setattr(self, key, value)
1108907
def _set_values(self):
        
        # Iterate all keys and values in data
        for k, v in self._data.items():
            # If it's a dict, process it (it's probably instance data)
            if isinstance(v, dict):
                try:
                    # Get related model from field (follow path)
                    rel_model = self._model
                    for attr in k.split('__'):
                        rel_model = getattr(rel_model, attr).field.related_model

                except AttributeError:
                    # Not a model, maybe it is a dict field (?)
                    pass

                else:
                    # Model, first shorten field name
                    k = k.replace('__', '_')

                    # Now init instance if required (not if we got ID None)
                    if 'id' in v and v['id'] is None:
                        # This means we grouped by ID, if it's none then FK is None
                        v = None

                    else:
                        # Either we have ID or we didn't group by ID, use instance
                        v = rel_model(**v)

            # Set value
            setattr(self, k, v)
1166172
def set_var(var, set_='""'):
    ''''''
    if isinstance(set_, str):
        to_set = json.dumps(set_)
    elif isinstance(set_, dict) or isinstance(set_, list):
        try:
            to_set = json.dumps(set_)
        except ValueError:
            raise Exception('var not jsonable')
    else:
        raise Exception('var must be jsonable list or dict')

    os.environ['NBCONVERT_' + var] = to_set
542455
def set_value(obj, attrs, value, _copy=False):
    
    for attr in attrs:
        if _copy:
            value = copy(value)
        setattr(obj, attr, value)
376570
def _set_property_dict_item(obj, prop, key, value):
    ''' 
    '''
    attr = getattr(obj, prop)
    if prop == 'devices':
        device_type = value['type']

        if device_type == 'disk':

            if 'path' not in value:
                raise SaltInvocationError(
                    "path must be given as parameter"
                )

            if value['path'] != '/' and 'source' not in value:
                raise SaltInvocationError(
                    "source must be given as parameter"
                )

        for k in value.keys():
            if k.startswith('__'):
                del value[k]

        attr[key] = value

    else:  # config
        attr[key] = six.text_type(value)

    pylxd_save_object(obj)

    return _pylxd_model_to_dict(obj)
1370407
def _get_values(cls, diff_dict, type='new'):
        '''
        
        '''
        ret_dict = {}
        for p in diff_dict.keys():
            if type in diff_dict[p].keys():
                ret_dict.update({p: diff_dict[p][type]})
            else:
                ret_dict.update(
                    {p: cls._get_values(diff_dict[p], type=type)})
        return ret_dict
655784
def set_dictionary(dictionary)
      dict = StringValue dictionary

      err = Zlib.deflateSetDictionary pointer, dict, dict.length

      Zlib.handle_error err, message

      dictionary
    end
107628
def set(self, instance, value, **kw):  # noqa
        
        ref = []

        # The value is an UID
        if api.is_uid(value):
            ref.append(api.get_object_by_uid(value))

        # The value is already an object
        if api.is_at_content(value):
            ref.append(value)

        # The value is a dictionary
        # -> handle it like a catalog query
        if u.is_dict(value):
            results = api.search(portal_type=self.allowed_types, **value)
            ref = map(api.get_object, results)

        # The value is a list
        if u.is_list(value):
            for item in value:
                # uid
                if api.is_uid(item):
                    ref.append(api.get_object_by_uid(item))
                    continue

                # object
                if api.is_at_content(item):
                    ref.append(api.get_object(item))
                    continue

                # path
                if api.is_path(item):
                    ref.append(api.get_object_by_path(item))
                    continue

                # dict (catalog query)
                if u.is_dict(item):
                    # If there is UID of objects, just use it.
                    uid = item.get('uid', None)
                    if uid:
                        obj = api.get_object_by_uid(uid)
                        ref.append(obj)
                    else:
                        results = api.search(portal_type=self.allowed_types, **item)
                        objs = map(api.get_object, results)
                        ref.extend(objs)
                    continue

                # Plain string
                # -> do a catalog query for title
                if isinstance(item, basestring):
                    results = api.search(portal_type=self.allowed_types, title=item)
                    objs = map(api.get_object, results)
                    ref.extend(objs)
                    continue

        # The value is a physical path
        if api.is_path(value):
            ref.append(api.get_object_by_path(value))

        # Handle non multi valued fields
        if not self.multi_valued:
            if len(ref) > 1:
                raise ValueError("Multiple values given for single valued "
                                 "field {}".format(repr(self.field)))
            else:
                ref = ref[0]
        return self._set(instance, ref, **kw)
103813
def copy_from_dict(self, attributes):
    
    for attribute_name, attribute_value in attributes.items():
      # Not using startswith to improve performance.
      if attribute_name[0] == '_':
        continue
      setattr(self, attribute_name, attribute_value)
1209633
def setdict(self, D):
        """"""

        self.D = np.asarray(D, dtype=self.dtype)
1039678
def simple_dict() -> Callable:
    

    def parse(dict_str: str):

        def _parse(value: str):
            if value == "True":
                return True
            if value == "False":
                return False
            if "." in value:
                return float(value)
            return int(value)

        _dict = dict()
        try:
            for entry in dict_str.split(","):
                key, value = entry.split(":")
                _dict[key] = _parse(value)
        except ValueError:
            raise argparse.ArgumentTypeError("Specify argument dictionary as key1:value1,key2:value2,..."
                                             " Supported types: bool, int, float.")
        return _dict

    return parse
748419
def setattrs(obj, **kwargs):
    
    for key, value in kwargs.items():
        setattr(obj, key, value)
    return obj
933370
def dict_copy(func):
    ""
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        copied_kwargs = copy.deepcopy(kwargs)
        return func(*args, **copied_kwargs)
    return wrapper
260677
def _MI_setitem(self, args, value):
    ''
    indices = self.indices
    N = len(indices)
    empty = N == 0
    if empty: # init the dict
        index1, key, index2, index1_last = MI_parse_args(self, args, allow_new=True)
        exist_names = [index1]
        item = [key]
        try:
            MI_check_index_name(index2)
            exist_names.append(index2)
            item.append(value)
        except TypeError:
            Nvalue, value = get_value_len(value)
            if len(index2) != Nvalue:
                raise ValueError(
                    'Number of keys (%s) based on argument %s does not match '
                    'number of values (%s)' % (len(index2), index2, Nvalue))
            exist_names.extend(index2)
            item.extend(value)
        if index1_last:
            exist_names = exist_names[1:] + exist_names[:1]
            item = item[1:] + item[:1]

        _MI_init(self, [item], exist_names)
        return

    index1, key, index2, item, old_value = MI_parse_args(self, args, allow_new=True)
    names = force_list(indices.keys())
    is_new_key = item is None
    single = isinstance(index2, int)

    if single:
        index2_list = [index2]
        value = [value]
        old_value = [old_value]
    else:
        index2_list = index2
        Nvalue, value = get_value_len(value)
        if len(index2_list) != Nvalue:
            raise ValueError('Number of keys (%s) based on argument %s does not match '
                             'number of values (%s)' % (len(index2_list), index2, Nvalue))
        if is_new_key:
            old_value = [None] * Nvalue  # fake it

    # remove duplicate in index2_list
    index2_d = OrderedDict()
    for e, index in enumerate(index2_list):
        index2_d[index] = e # order of each unique index
    if len(index2_d) < len(index2_list): # exist duplicate indices
        idx = index2_d.values()
        index2_list = mget_list(index2_list, idx)
        value = mget_list(value, idx)
        old_value = mget_list(old_value, idx)

    # check duplicate values
    for i, v, old_v in zip(index2_list, value, old_value):
        # index2_list may contain index1; not allow duplicate value for index1 either
        if v in indices[i]:
            if is_new_key or v != old_v:
                raise ValueExistsError(v, i, names[i])

    if is_new_key:
        if set(index2_list + [index1]) != set(range(N)):
            raise ValueError('Indices of the new item do not match existing indices')

        d = {}
        d[index1] = key
        # index2_list may also override index1
        d.update(zip(index2_list, value))
        values = [d[i] for i in range(N)]  # reorder based on the indices
        key = values[0]
        val = values[1] if len(values) == 2 else values[1:]
        super(MIMapping, self).__setitem__(key, val)
        for i, v in zip(names[1:], values[1:]):
            indices[i][v] = key

    else: # not new key
#        import pdb;pdb.set_trace()
        key1 = item[0]
        item2 = list(item)  # copy item first
        mset_list(item2, index2_list, value) # index2_list may also override index1
        key2 = item2[0]
        val = item2[1] if len(item2) == 2 else item2[1:]
        if key1 == key2:
            super(MIMapping, self).__setitem__(key1, val)
        else:
            od_replace_key(self, key1, key2, val)

        for i, v_old, v_new in zip(names[1:], item[1:], item2[1:]):
            od_replace_key(indices[i], v_old, v_new, key2)