Python __builtin__.range() Examples
The following are 30
code examples of __builtin__.range().
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
__builtin__
, or try the search function
.
Example #1
Source File: python.py From Splunking-Crime with GNU Affero General Public License v3.0 | 6 votes |
def combinations(iterable, r): # combinations('ABCD', 2) --> AB AC AD BC BD CD # combinations(lrange(4), 3) --> 012 013 023 123 pool = tuple(iterable) n = len(pool) if r > n: return indices = lrange(r) yield tuple(pool[i] for i in indices) while True: for i in reversed(lrange(r)): if indices[i] != i + n - r: break else: return indices[i] += 1 for j in range(i+1, r): indices[j] = indices[j-1] + 1 yield tuple(pool[i] for i in indices)
Example #2
Source File: __init__.py From recruit with Apache License 2.0 | 6 votes |
def get_range_parameters(data): """Gets the start, stop, and step parameters from a range object""" # seems we only have indexing ops to infer # rather than direct accessors if len(data) > 1: step = data[1] - data[0] stop = data[-1] + step start = data[0] elif len(data): start = data[0] stop = data[0] + 1 step = 1 else: start = stop = 0 step = 1 return start, stop, step # import iterator versions of these functions
Example #3
Source File: __init__.py From twitter-stock-recommendation with MIT License | 6 votes |
def get_range_parameters(data): """Gets the start, stop, and step parameters from a range object""" # seems we only have indexing ops to infer # rather than direct accessors if len(data) > 1: step = data[1] - data[0] stop = data[-1] + step start = data[0] elif len(data): start = data[0] stop = data[0] + 1 step = 1 else: start = stop = 0 step = 1 return start, stop, step # import iterator versions of these functions
Example #4
Source File: python.py From vnpy_crypto with MIT License | 6 votes |
def combinations(iterable, r): # combinations('ABCD', 2) --> AB AC AD BC BD CD # combinations(lrange(4), 3) --> 012 013 023 123 pool = tuple(iterable) n = len(pool) if r > n: return indices = lrange(r) yield tuple(pool[i] for i in indices) while True: for i in reversed(lrange(r)): if indices[i] != i + n - r: break else: return indices[i] += 1 for j in range(i+1, r): indices[j] = indices[j-1] + 1 yield tuple(pool[i] for i in indices)
Example #5
Source File: __init__.py From coffeegrindsize with MIT License | 6 votes |
def get_range_parameters(data): """Gets the start, stop, and step parameters from a range object""" # seems we only have indexing ops to infer # rather than direct accessors if len(data) > 1: step = data[1] - data[0] stop = data[-1] + step start = data[0] elif len(data): start = data[0] stop = data[0] + 1 step = 1 else: start = stop = 0 step = 1 return start, stop, step # import iterator versions of these functions
Example #6
Source File: __init__.py From vnpy_crypto with MIT License | 6 votes |
def get_range_parameters(data): """Gets the start, stop, and step parameters from a range object""" # seems we only have indexing ops to infer # rather than direct accessors if len(data) > 1: step = data[1] - data[0] stop = data[-1] + step start = data[0] elif len(data): start = data[0] stop = data[0] + 1 step = 1 else: start = stop = 0 step = 1 return start, stop, step # import iterator versions of these functions
Example #7
Source File: __init__.py From Computable with MIT License | 6 votes |
def elements(self): """Iterator over elements repeating each as many times as its count. >>> c = Counter('ABCABC') >>> sorted(c.elements()) ['A', 'A', 'B', 'B', 'C', 'C'] If an element's count has been set to zero or is a negative number, elements() will ignore it. """ for elem, count in iteritems(self): for _ in range(count): yield elem # Override dict methods where the meaning changes for Counter objects.
Example #8
Source File: pandas_py3k.py From kgsgo-dataset-preprocessor with Mozilla Public License 2.0 | 6 votes |
def elements(self): '''Iterator over elements repeating each as many times as its count. >>> c = Counter('ABCABC') >>> sorted(c.elements()) ['A', 'A', 'B', 'B', 'C', 'C'] If an element's count has been set to zero or is a negative number, elements() will ignore it. ''' for elem, count in iteritems(self): for _ in range(count): yield elem # Override dict methods where the meaning changes for Counter objects.
Example #9
Source File: __init__.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def get_range_parameters(data): """Gets the start, stop, and step parameters from a range object""" # seems we only have indexing ops to infer # rather than direct accessors if len(data) > 1: step = data[1] - data[0] stop = data[-1] + step start = data[0] elif len(data): start = data[0] stop = data[0] + 1 step = 1 else: start = stop = 0 step = 1 return start, stop, step # import iterator versions of these functions
Example #10
Source File: __init__.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def get_range_parameters(data): """Gets the start, stop, and step parameters from a range object""" # seems we only have indexing ops to infer # rather than direct accessors if len(data) > 1: step = data[1] - data[0] stop = data[-1] + step start = data[0] elif len(data): start = data[0] stop = data[0] + 1 step = 1 else: start = stop = 0 step = 1 return start, stop, step # import iterator versions of these functions
Example #11
Source File: __init__.py From Splunking-Crime with GNU Affero General Public License v3.0 | 6 votes |
def get_range_parameters(data): """Gets the start, stop, and step parameters from a range object""" # seems we only have indexing ops to infer # rather than direct accessors if len(data) > 1: step = data[1] - data[0] stop = data[-1] + step start = data[0] elif len(data): start = data[0] stop = data[0] + 1 step = 1 else: start = stop = 0 step = 1 return start, stop, step # import iterator versions of these functions
Example #12
Source File: __init__.py From Tautulli with GNU General Public License v3.0 | 5 votes |
def lrange(*args, **kwargs): return list(range(*args, **kwargs))
Example #13
Source File: __init__.py From gimp-plugin-export-layers with GNU General Public License v3.0 | 5 votes |
def lrange(*args, **kwargs): return list(range(*args, **kwargs))
Example #14
Source File: test_board.py From term2048-AI with MIT License | 5 votes |
def test_xrange_fallback_on_range_on_py3k(self): self.assertEqual(board.xrange, __builtin__.range)
Example #15
Source File: __init__.py From coffeegrindsize with MIT License | 5 votes |
def get_range_parameters(data): """Gets the start, stop, and step parameters from a range object""" return data.start, data.stop, data.step # have to explicitly put builtins into the namespace
Example #16
Source File: __init__.py From twitter-stock-recommendation with MIT License | 5 votes |
def lrange(*args, **kwargs): return list(range(*args, **kwargs))
Example #17
Source File: __init__.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def lrange(*args, **kwargs): return list(range(*args, **kwargs))
Example #18
Source File: __init__.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def get_range_parameters(data): """Gets the start, stop, and step parameters from a range object""" return data.start, data.stop, data.step # have to explicitly put builtins into the namespace
Example #19
Source File: __coconut__.py From pyprover with Apache License 2.0 | 5 votes |
def __call__(self, *args, **kwargs): callargs = [] argind = 0 for i in _coconut.range(self._arglen): if i in self._argdict: callargs.append(self._argdict[i]) elif argind >= _coconut.len(args): raise _coconut.TypeError("expected at least " + _coconut.str(self._arglen - _coconut.len(self._argdict)) + " argument(s) to " + _coconut.repr(self)) else: callargs.append(args[argind]) argind += 1 callargs += self._stargs callargs += args[argind:] kwargs.update(self.keywords) return self.func(*callargs, **kwargs)
Example #20
Source File: python.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def lrange(*args, **kwargs): return list(range(*args, **kwargs))
Example #21
Source File: compatibility_utils.py From fb2mobi with MIT License | 5 votes |
def lrange(*args, **kwargs): return list(range(*args, **kwargs))
Example #22
Source File: setup.py From pyprover with Apache License 2.0 | 5 votes |
def makedata(data_type, *args): """Construct an object of the given data_type containing the given arguments.""" if _coconut.hasattr(data_type, "_make") and _coconut.issubclass(data_type, _coconut.tuple): return data_type._make(args) if _coconut.issubclass(data_type, (_coconut.map, _coconut.range, _coconut.abc.Iterator)): return args if _coconut.issubclass(data_type, _coconut.str): return "".join(args) return data_type(args)
Example #23
Source File: setup.py From pyprover with Apache License 2.0 | 5 votes |
def __repr__(self): args = [] for i in _coconut.range(self._arglen): if i in self._argdict: args.append(_coconut.repr(self._argdict[i])) else: args.append("?") for arg in self._stargs: args.append(_coconut.repr(arg)) return _coconut.repr(self.func) + "$(" + ", ".join(args) + ")"
Example #24
Source File: setup.py From pyprover with Apache License 2.0 | 5 votes |
def __call__(self, *args, **kwargs): callargs = [] argind = 0 for i in _coconut.range(self._arglen): if i in self._argdict: callargs.append(self._argdict[i]) elif argind >= _coconut.len(args): raise _coconut.TypeError("expected at least " + _coconut.str(self._arglen - _coconut.len(self._argdict)) + " argument(s) to " + _coconut.repr(self)) else: callargs.append(args[argind]) argind += 1 callargs += self._stargs callargs += args[argind:] kwargs.update(self.keywords) return self.func(*callargs, **kwargs)
Example #25
Source File: setup.py From pyprover with Apache License 2.0 | 5 votes |
def args(self): return _coconut.tuple(self._argdict.get(i) for i in _coconut.range(self._arglen)) + self._stargs
Example #26
Source File: setup.py From pyprover with Apache License 2.0 | 5 votes |
def __getitem__(self, index): if _coconut.isinstance(index, _coconut.slice) and (index.start is None or index.start >= 0) and (index.stop is None or index.stop >= 0): new_start, new_step = self.start, self.step if self.step and index.start is not None: new_start += self.step * index.start if self.step and index.step is not None: new_step *= index.step if index.stop is None: return self.__class__(new_start, new_step) if self.step and _coconut.isinstance(self.start, _coconut.int) and _coconut.isinstance(self.step, _coconut.int): return _coconut.range(new_start, self.start + self.step * index.stop, new_step) return _coconut_map(self.__getitem__, _coconut.range(index.start if index.start is not None else 0, index.stop, index.step if index.step is not None else 1)) if index < 0: raise _coconut.IndexError("count indices must be positive") return self.start + self.step * index if self.step else self.start
Example #27
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 #28
Source File: setup.py From pyprover with Apache License 2.0 | 5 votes |
def tee(iterable, n=2): if n >= 0 and _coconut.isinstance(iterable, (_coconut.tuple, _coconut.frozenset)): return (iterable,) * n if n > 0 and (_coconut.hasattr(iterable, "__copy__") or _coconut.isinstance(iterable, _coconut.abc.Sequence)): return (iterable,) + _coconut.tuple(_coconut.copy.copy(iterable) for _ in _coconut.range(n - 1)) return _coconut.itertools.tee(iterable, n)
Example #29
Source File: setup.py From pyprover with Apache License 2.0 | 5 votes |
def xrange(*args): """Coconut uses Python 3 "range" instead of Python 2 "xrange".""" raise _coconut.NameError('Coconut uses Python 3 "range" instead of Python 2 "xrange"')
Example #30
Source File: fypp.py From fypp with BSD 2-Clause "Simplified" License | 5 votes |
def _func_setvar(self, *namesvalues): if len(namesvalues) % 2: msg = 'setvar function needs an even number of arguments' raise FyppFatalError(msg) for ind in range(0, len(namesvalues), 2): self.define(namesvalues[ind], namesvalues[ind + 1])