Skip to content

Instantly share code, notes, and snippets.

@lxfly2000
Created September 24, 2018 09:15
Show Gist options
  • Save lxfly2000/4a4ab4ed18bb39044b1008a1eb4dbd48 to your computer and use it in GitHub Desktop.
Save lxfly2000/4a4ab4ed18bb39044b1008a1eb4dbd48 to your computer and use it in GitHub Desktop.
#encoding=utf-8
#Python 生成器的应用
#把普通的遍历完后产生返回的集合对象过程(整体返回)改为一边遍历一边返回集合中对象的过程(交错返回)
def GetSomeNumbers(stopTag):
if stopTag==0:
print("遍历所有数值")
if stopTag==1:
return
yield 213
yield 271
if stopTag==2:
return
yield 12450
if stopTag==3:
return
yield 114514
yield 1919
yield 810
if stopTag==4:
return
yield 12450
def main():
print("生成器:")
for n in GetSomeNumbers(0):
print(n)
listNumbers={1,1,4,5,1,4,1,9,1,9,8,1,0}
print("数组列表:")
for m in listNumbers:
print(m)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment