def __setitem__(self, key, data):
        """ x.__setitem__(i, y) <==> x[i]=y """

        if not self._writeable:
            raise AttributeError("List is not writeable")

        if isinstance(key, (int, slice)):
            if isinstance(key, int):
                if key < 0:
                    key += len(self)
                if key < 0 or key > len(self):
                    raise IndexError("List assignment index out of range")
                dstart = self._items[key][0]
                dstop = self._items[key][1]
                istart = key
            elif isinstance(key, slice):
                istart, istop, step = key.indices(len(self))
                if istart == istop:
                    return
                if istart > istop:
                    istart, istop = istop, istart
                if istart > len(self) or istop > len(self):
                    raise IndexError("Can only assign iterable")
                dstart = self._items[istart][0]
                if istart == istop:
                    dstop = dstart
                else:
                    dstop = self._items[istop - 1][1]

            if hasattr(data, "__len__"):
                if len(data) == dstop - dstart:  # or len(data) == 1:
                    self._data[dstart:dstop] = data
                else:
                    self.__delitem__(key)
                    self.insert(istart, data)
            else:  # we assume len(data) = 1
                if dstop - dstart == 1:
                    self._data[dstart:dstop] = data
                else:
                    self.__delitem__(key)
                    self.insert(istart, data)

        elif key is Ellipsis:
            self.data[...] = data

        elif isinstance(key, str):
            self._data[key][:self._size] = data

        else:
            raise TypeError("List assignment indices must be integers")
def __setitem__ ( self , key , data ) : if not self . _writeable : raise AttributeError ( "List is not writeable" ) if isinstance ( key , ( int , slice ) ) : if isinstance ( key , int ) : if key < 0 : key += len ( self ) if key < 0 or key > len ( self ) : raise IndexError ( "List assignment index out of range" ) dstart = self . _items [ key ] [ 0 ] dstop = self . _items [ key ] [ 1 ] istart = key elif isinstance ( key , slice ) : istart , istop , step = key . indices ( len ( self ) ) if istart == istop : return if istart > istop : istart , istop = istop , istart if istart > len ( self ) or istop > len ( self ) : raise IndexError ( "Can only assign iterable" ) dstart = self . _items [ istart ] [ 0 ] if istart == istop : dstop = dstart else : dstop = self . _items [ istop - 1 ] [ 1 ] if hasattr ( data , "__len__" ) : if len ( data ) == dstop - dstart : self . _data [ dstart : dstop ] = data else : self . __delitem__ ( key ) self . insert ( istart , data ) else : if dstop - dstart == 1 : self . _data [ dstart : dstop ] = data else : self . __delitem__ ( key ) self . insert ( istart , data ) elif key is Ellipsis : self . data [ ... ] = data elif isinstance ( key , str ) : self . _data [ key ] [ : self . _size ] = data else : raise TypeError ( "List assignment indices must be integers" )
x.__setitem__(i, y) <==> x[i]=y