Skip to content

Instantly share code, notes, and snippets.

@thecraftman
Last active July 4, 2021 21:19
Show Gist options
  • Save thecraftman/d7cfe5e7d945f2a6afb1f0f261245ba2 to your computer and use it in GitHub Desktop.
Save thecraftman/d7cfe5e7d945f2a6afb1f0f261245ba2 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])
print my_nums
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment