Python builtins.reversed() Examples
The following are 18
code examples of builtins.reversed().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
builtins
, or try the search function
.
Example #1
Source File: __coconut__.py From pyprover with Apache License 2.0 | 5 votes |
def index(self, elem): """Find the index of elem in the reversed iterator.""" return _coconut.len(self.iter) - self.iter.index(elem) - 1
Example #2
Source File: sanity.py From reframe with BSD 3-Clause "New" or "Revised" License | 5 votes |
def reversed(seq): '''Replacement for the built-in :func:`reversed() <python:reversed>` function.''' return builtins.reversed(seq)
Example #3
Source File: setup.py From pyprover with Apache License 2.0 | 5 votes |
def count(self, elem): """Count the number of times elem appears in the reversed iterator.""" return self.iter.count(elem)
Example #4
Source File: setup.py From pyprover with Apache License 2.0 | 5 votes |
def __repr__(self): return "reversed(%r)" % (self.iter,)
Example #5
Source File: setup.py From pyprover with Apache License 2.0 | 5 votes |
def __iter__(self): return _coconut.iter(_coconut.reversed(self.iter))
Example #6
Source File: setup.py From pyprover with Apache License 2.0 | 5 votes |
def __new__(cls, iterable): if _coconut.isinstance(iterable, _coconut.range): return iterable[::-1] if not _coconut.hasattr(iterable, "__reversed__") or _coconut.isinstance(iterable, (_coconut.list, _coconut.tuple)): return _coconut.object.__new__(cls) return _coconut.reversed(iterable)
Example #7
Source File: setup.py From pyprover with Apache License 2.0 | 5 votes |
def _coconut_back_dubstar_compose(*funcs): return _coconut_forward_dubstar_compose(*_coconut.reversed(funcs))
Example #8
Source File: setup.py From pyprover with Apache License 2.0 | 5 votes |
def _coconut_back_compose(*funcs): return _coconut_forward_compose(*_coconut.reversed(funcs))
Example #9
Source File: setup.py From pyprover with Apache License 2.0 | 5 votes |
def __reversed__(self): return _coconut.reversed(self._xrange)
Example #10
Source File: __coconut__.py From pyprover with Apache License 2.0 | 5 votes |
def count(self, elem): """Count the number of times elem appears in the reversed iterator.""" return self.iter.count(elem)
Example #11
Source File: __coconut__.py From pyprover with Apache License 2.0 | 5 votes |
def __repr__(self): return "reversed(%r)" % (self.iter,)
Example #12
Source File: __coconut__.py From pyprover with Apache License 2.0 | 5 votes |
def __new__(cls, iterable): if _coconut.isinstance(iterable, _coconut.range): return iterable[::-1] if not _coconut.hasattr(iterable, "__reversed__") or _coconut.isinstance(iterable, (_coconut.list, _coconut.tuple)): return _coconut.object.__new__(cls) return _coconut.reversed(iterable)
Example #13
Source File: __coconut__.py From pyprover with Apache License 2.0 | 5 votes |
def _coconut_back_dubstar_compose(*funcs): return _coconut_forward_dubstar_compose(*_coconut.reversed(funcs))
Example #14
Source File: __coconut__.py From pyprover with Apache License 2.0 | 5 votes |
def _coconut_back_star_compose(*funcs): return _coconut_forward_star_compose(*_coconut.reversed(funcs))
Example #15
Source File: __coconut__.py From pyprover with Apache License 2.0 | 5 votes |
def _coconut_back_compose(*funcs): return _coconut_forward_compose(*_coconut.reversed(funcs))
Example #16
Source File: __coconut__.py From pyprover with Apache License 2.0 | 5 votes |
def __reversed__(self): return _coconut.reversed(self._xrange)
Example #17
Source File: core.py From pythonflow with Apache License 2.0 | 5 votes |
def evaluate_operation(cls, operation, context, **kwargs): """ Evaluate an operation or constant given a context. """ try: if isinstance(operation, Operation): return operation.evaluate(context, **kwargs) partial = functools.partial(cls.evaluate_operation, context=context, **kwargs) if isinstance(operation, tuple): return tuple(partial(element) for element in operation) if isinstance(operation, list): return [partial(element) for element in operation] if isinstance(operation, dict): return {partial(key): partial(value) for key, value in operation.items()} if isinstance(operation, slice): return slice(*[partial(getattr(operation, attr)) for attr in ['start', 'stop', 'step']]) return operation except Exception as ex: # pragma: no cover stack = [] interactive = False for frame in reversed(operation._stack): # pylint: disable=protected-access # Do not capture any internal stack traces if 'pythonflow' in frame.filename: continue # Stop tracing at the last interactive cell if interactive and not frame.filename.startswith('<'): break # pragma: no cover interactive = frame.filename.startswith('<') stack.append(frame) stack = "".join(traceback.format_list(reversed(stack))) message = "Failed to evaluate operation `%s` defined at:\n\n%s" % (operation, stack) raise ex from EvaluationError(message)
Example #18
Source File: pyRMT.py From pyRMT with MIT License | 4 votes |
def checkDesignMatrix(X): """ Parameters ---------- X: a matrix of shape (T, N), where T denotes the number of samples and N labels the number of features. If T < N, a warning is issued to the user, and the transpose of X is considered instead. Returns: T: type int N: type int transpose_flag: type bool Specify if the design matrix X should be transposed in view of having less rows than columns. """ try: assert isinstance(X, (np.ndarray, pd.DataFrame, pd.Series, MutableSequence, Sequence)) except AssertionError: raise sys.exit(1) X = np.asarray(X, dtype=float) X = np.atleast_2d(X) if X.shape[0] < X.shape[1]: warnings.warn("The Marcenko-Pastur distribution pertains to " "the empirical covariance matrix of a random matrix X " "of shape (T, N). It is assumed that the number of " "samples T is assumed higher than the number of " "features N. The transpose of the matrix X submitted " "at input will be considered in the cleaning schemes " "for the corresponding correlation matrix.", UserWarning) T, N = reversed(X.shape) transpose_flag = True else: T, N = X.shape transpose_flag = False return T, N, transpose_flag