Last active
July 4, 2021 21:17
-
-
Save thecraftman/f50ae964798243798e4fb6a1b874a762 to your computer and use it in GitHub Desktop.
Python Generators
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def square_numbers(nums): | |
for i in nums: | |
yield(i*i) | |
my_nums = square_numbers([1, 2, 3, 4, 5]) | |
print next(my_nums) | |
print next(my_nums) | |
print next(my_nums) | |
print next(my_nums) | |
print next(my_nums) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment