Skip to content

Instantly share code, notes, and snippets.

@artturijalli
Created April 21, 2021 09:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artturijalli/326760cb95ece7069ca17496eeeb5ef1 to your computer and use it in GitHub Desktop.
Save artturijalli/326760cb95ece7069ca17496eeeb5ef1 to your computer and use it in GitHub Desktop.
A simple generator in Python
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