def __setitem__(self, index, value):
<EOL>_lists = self._lists<EOL>_keys = self._keys<EOL>_maxes = self._maxes<EOL>_check_order = self._check_order<EOL>_pos = self._pos<EOL>if isinstance(index, slice):<EOL><INDENT>_len = self._len<EOL>start, stop, step = index.indices(_len)<EOL>indices = range(start, stop, step)<EOL>values = tuple(value)<EOL>if step != <NUM_LIT:1>:<EOL><INDENT>if len(values) != len(indices):<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>% (len(values), len(indices)))<EOL><DEDENT>log = []<EOL>_append = log.append<EOL>for idx, val in zip(indices, values):<EOL><INDENT>pos, loc = _pos(idx)<EOL>key = self._key(val)<EOL>_append((idx, _keys[pos][loc], key, _lists[pos][loc], val))<EOL>_keys[pos][loc] = key<EOL>_lists[pos][loc] = val<EOL>if len(_keys[pos]) == (loc + <NUM_LIT:1>):<EOL><INDENT>_maxes[pos] = key<EOL><DEDENT><DEDENT>try:<EOL><INDENT>for idx, oldkey, newkey, oldval, newval in log:<EOL><INDENT>_check_order(idx, newkey, newval)<EOL><DEDENT><DEDENT>except ValueError:<EOL><INDENT>for idx, oldkey, newkey, oldval, newval in log:<EOL><INDENT>pos, loc = _pos(idx)<EOL>_keys[pos][loc] = oldkey<EOL>_lists[pos][loc] = oldval<EOL>if len(_keys[pos]) == (loc + <NUM_LIT:1>):<EOL><INDENT>_maxes[pos] = oldkey<EOL><DEDENT><DEDENT>raise<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if start == <NUM_LIT:0> and stop == self._len:<EOL><INDENT>self._clear()<EOL>return self._update(values)<EOL><DEDENT>if stop < start:<EOL><INDENT>stop = start<EOL><DEDENT>if values:<EOL><INDENT>keys = tuple(map(self._key, values))<EOL>alphas = iter(keys)<EOL>betas = iter(keys)<EOL>next(betas)<EOL>pairs = zip(alphas, betas)<EOL>if not all(alpha <= beta for alpha, beta in pairs):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if start:<EOL><INDENT>pos, loc = _pos(start - <NUM_LIT:1>)<EOL>if _keys[pos][loc] > keys[<NUM_LIT:0>]:<EOL><INDENT>msg = '<STR_LIT>'.format(<EOL>values[<NUM_LIT:0>], start)<EOL>raise ValueError(msg)<EOL><DEDENT><DEDENT>if stop != _len:<EOL><INDENT>pos, loc = _pos(stop)<EOL>if _keys[pos][loc] < keys[-<NUM_LIT:1>]:<EOL><INDENT>msg = '<STR_LIT>'.format(<EOL>values[-<NUM_LIT:1>], stop)<EOL>raise ValueError(msg)<EOL><DEDENT><DEDENT><DEDENT>self._delitem(index)<EOL>_insert = self.insert<EOL>for idx, val in enumerate(values):<EOL><INDENT>_insert(start + idx, val)<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>pos, loc = _pos(index)<EOL>key = self._key(value)<EOL>_check_order(index, key, value)<EOL>_lists[pos][loc] = value<EOL>_keys[pos][loc] = key<EOL>if len(_lists[pos]) == (loc + <NUM_LIT:1>):<EOL><INDENT>_maxes[pos] = key<EOL><DEDENT><DEDENT>
Replace the item at position *index* with *value*.

        Supports slice notation. Raises a :exc:`ValueError` if the sort order
        would be violated. When used with a slice and iterable, the
        :exc:`ValueError` is raised before the list is mutated if the sort
        order would be violated by the operation.