コード例 #1
0
 def pop(self, index=-1):
     '''Remove an item from this list, like C{list.pop}.
     '''
     i = _at(self, index)
     v = self[i]
     del self[i]  # __delitem__
     return v
コード例 #2
0
 def __delitem__(self, index):
     if isinstance(index, slice):
         indices = range(*index.indices(len(self)))
         for i in sorted(indices, reverse=True):
             self.NS.removeObjectAtIndex_(i)
     else:
         self.NS.removeObjectAtIndex_(_at(self, index))
コード例 #3
0
 def __setitem__(self, index, value):
     if isinstance(index, slice):
         indices = range(*index.indices(len(self)))
         for i, val in zip_longest(indices, value, fillvalue=missing):
             if missing in (i, val):  # XXX only if val is missing?
                 raise ValueError('%s len() mismatch %r vs %r' %
                                  (self, index, value))
             self.NS.replaceObjectAtIndex_withObject_(i, py2NS(val))
     else:
         self.NS.replaceObjectAtIndex_withObject_(_at(self, index), py2NS(value))
コード例 #4
0
 def insert(self, index, value):
     '''Insert an item into this list, like C{list.insert}.
     '''
     self.NS.insertObject_atIndex_(py2NS(value), _at(self, index))