每天CookBook之Python-063

  • 对迭代器使用slice
def count(n):
    while True:
        yield n
        n += 1

c = count(0)

import itertools

for x in itertools.islice(c, 10, 20):
    print(x)

out

10
11
12
13
14
15
16
17
18
19
posted @ 2016-07-22 20:40  4Thing  阅读(77)  评论(0编辑  收藏  举报