Skip to content

Instantly share code, notes, and snippets.

@2tony2
Created July 5, 2024 16:12
Show Gist options
  • Save 2tony2/c9c3d045f1663fbcb548b6d79e7921d3 to your computer and use it in GitHub Desktop.
Save 2tony2/c9c3d045f1663fbcb548b6d79e7921d3 to your computer and use it in GitHub Desktop.
def count_up_to(max):
count = 1
while count <= max:
yield count
count += 1
counter = count_up_to(3)
print(next(counter)) # Output: 1
print(next(counter)) # Output: 2
print(next(counter)) # Output: 3
# Calling next again will raise StopIteration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment