0 前言
说到处理循环,我们习惯使用for, while等,比如依次打印每个列表中的字符:
lis = ['I', 'love', 'python']
for i in lis:
print(..., stop[, step])
应用例子:
In [41]: list(islice('abcdefg',1,4,2))
Out[41]: ['b', 'd']
实现它的大概代码如下:
def islice...(iterable, *args):
s = slice(*args)
start, stop, step = s.start or 0, s.stop or sys.maxsize,...s.step or 1
it = iter(range(start, stop, step))
try:
nexti = next(it)
except StopIteration...repeat(object, times=None):
if times is None:# 如果times不设置,将一直repeat下去
while True: