Skip to content

Instantly share code, notes, and snippets.

@dawranliou
Created April 26, 2018 00:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dawranliou/5209ab21cdfd8e9e59f0011fd30078a4 to your computer and use it in GitHub Desktop.
Save dawranliou/5209ab21cdfd8e9e59f0011fd30078a4 to your computer and use it in GitHub Desktop.
def tri_gen():
tri_num = 0
n = 1
while True:
yield tri_num
tri_num += n
n += 1
tri_numbers = tri_gen()
next(tri_numbers) # 0
next(tri_numbers) # 1
next(tri_numbers) # 3
next(tri_numbers) # 6
next(tri_numbers) # 10
next(tri_numbers) # 15
next(tri_numbers) # 21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment