Created
April 21, 2021 09:00
-
-
Save artturijalli/326760cb95ece7069ca17496eeeb5ef1 to your computer and use it in GitHub Desktop.
A simple generator in Python
This file contains 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_even(numbers): | |
for number in numbers: | |
if number % 2 == 0: | |
yield(number * number) | |
numbers = [1, 2, 3, 4, 5, 6] | |
squared_numbers = square_even(numbers) | |
for number in squared_numbers: | |
print(number) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment