Пример #1
0
 def index(self, value, start=None, stop=None):
     """Return the index of the first occurance of C{value} in this
     list that is greater than or equal to C{start} and less than
     C{stop}.  Negative start & stop values are treated like negative
     slice bounds -- i.e., they count from the end of the list."""
     start, stop = slice_bounds(self, slice(start, stop))
     for i, elt in enumerate(islice(self, start, stop)):
         if elt == value: return i+start
     raise ValueError('index(x): x not in list')
Пример #2
0
 def __getitem__(self, i):
     """
     Return the C{i}th token in the corpus file underlying this
     corpus view.  Negative indices and spans are both supported.
     """
     if isinstance(i, slice):
         start, stop = slice_bounds(self, i)
         return LazySubsequence(self, start, stop)
     else:
         # Handle negative indices
         if i < 0: i += len(self)
         if i < 0: raise IndexError('index out of range')
         # Use iterate_from to extract it.
         try:
             return self.iterate_from(i).next()
         except StopIteration:
             raise IndexError('index out of range')