Skip to content

Instantly share code, notes, and snippets.

@thecraftman
Last active July 4, 2021 21:18
Show Gist options
  • Save thecraftman/159c1601e0f48d3595961f22a796b2cf to your computer and use it in GitHub Desktop.
Save thecraftman/159c1601e0f48d3595961f22a796b2cf to your computer and use it in GitHub Desktop.
Python Generator
def square_numbers(nums):
for i in nums:
yield(i*i)
my_nums = square_numbers([1, 2, 3, 4, 5])
for num in my_nums:
print num
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment