标签:return class 取值 can IV iter += start tar
l = [0,1,2,3,4,5,6,7,8,9,] #模拟一个大列表 def list_scan_iter(L): start = 0 #从0开始取值 while True: # 第一次:0,1,2,3 # 第二次:4,5,6,7 # 第三次:8,9 vals = L[start:start+4] #每次取4个值 start += 4 if not vals: #vals=[]时 return for val in vals: yield val ret = list_scan_iter(l) for i in ret: print(i)
结果:
0
1
2
3
4
5
6
7
8
9
标签:return class 取值 can IV iter += start tar
原文地址:https://www.cnblogs.com/dylan-wu/p/9129862.html