def set(self, key, val, to_global=False):
        """
        Set a value to specified key in dictionary

        @param key: a key to set value
        @param val: a value to be set, if provided as not None
            otherwise key will be deleted instead
        @param to_global: a boolean specified whether set the value to
            global dictionary or local dictionary
        """
        if val is None:
            if self.has(key, in_global=False, in_local=True):
                del self.local_dict[key]
                self.local_change = True
            elif self.has(key, in_global=True, in_local=False):
                del self.global_dict[key]
                self.global_change = True
        else:
            if to_global:
                if key not in self.global_dict or self.global_dict[key] != val:
                    self.global_dict[key] = val
                    self.global_change = True
            else:
                if key not in self.local_dict or self.local_dict[key] != val:
                    self.local_dict[key] = val
                    self.local_change = True
dataset/ETHPy150Open spywhere/Javatar/core/dict.py/JavatarDict.set/original