- 对迭代器使用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 本文介绍了一种使用Python中的itertools.islice方法来操作无限迭代器的方法。通过一个具体的例子展示了如何从一个无限生成整数的迭代器中截取特定范围内的元素。
本文介绍了一种使用Python中的itertools.islice方法来操作无限迭代器的方法。通过一个具体的例子展示了如何从一个无限生成整数的迭代器中截取特定范围内的元素。
          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转载于:https://www.cnblogs.com/4thing/p/5697071.html
 2118
					2118
					
				 1580
					1580
					
				
 被折叠的  条评论
		 为什么被折叠?
被折叠的  条评论
		 为什么被折叠?
		 
		  到【灌水乐园】发言
到【灌水乐园】发言                                
		 
		 
    
  