Exemplo n.º 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')
Exemplo n.º 2
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')
Exemplo n.º 3
0
 def index(self, value, start=None, stop=None):
     """Return the index of the first occurrence of ``value`` in this
     list that is greater than or equal to ``start`` and less than
     ``stop``.  Negative start and 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")
Exemplo n.º 4
0
 def index(self, value, start=None, stop=None):
     """Return the index of the first occurrence of ``value`` in this
     list that is greater than or equal to ``start`` and less than
     ``stop``.  Negative start and 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")
Exemplo n.º 5
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')
Exemplo n.º 6
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')
Exemplo n.º 7
0
 def __getitem__(self, i):
     if isinstance(i, slice):
         start, stop = slice_bounds(self, i)
         # Check if it's in the cache.
         offset = self._cache[0]
         if offset <= start and stop <= self._cache[1]:
             return self._cache[2][start-offset:stop-offset]
         # Construct & return the result.
         return LazySubsequence(self, start, stop)
     else:
         # Handle negative indices
         if i < 0: i += len(self)
         if i < 0: raise IndexError('index out of range')
         # Check if it's in the cache.
         offset = self._cache[0]
         if offset <= i < self._cache[1]:
             return self._cache[2][i-offset]
         # Use iterate_from to extract it.
         try:
             return next(self.iterate_from(i))
         except StopIteration:
             raise IndexError('index out of range')