本文整理汇总了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))