本文整理匯總了Python中__builtin__.range方法的典型用法代碼示例。如果您正苦於以下問題:Python __builtin__.range方法的具體用法?Python __builtin__.range怎麽用?Python __builtin__.range使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類__builtin__
的用法示例。
在下文中一共展示了__builtin__.range方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_range_parameters
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import range [as 別名]
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
示例2: combinations
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import range [as 別名]
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)
示例3: elements
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import range [as 別名]
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.
示例4: elements
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import range [as 別名]
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.
示例5: lrange
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import range [as 別名]
def lrange(*args, **kwargs):
return list(range(*args, **kwargs))
示例6: oldrange
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import range [as 別名]
def oldrange(*args, **kwargs):
return list(builtins.range(*args, **kwargs))