# a generator to be used for launching space shuttles
def countdown_gen():
''' calling it creates an iterator for the values 5,4,3,2,1,'launch' '''
yield 5
yield 4
yield 3
yield 2
yield 1
yield 'launch'
# a function which produces a list of all positive even numbers up to n
def Evens_list(n):
''' a list of evens up to n '''
return [num for num in range(n) if num%2==0]
# a generator which produces all positive even numbers up to n
def Evens_gen(n):
''' a generator of evens up to n '''
for i in range(n):
if i%2 == 0:
yield i
# exactly the same as Evens_gen but with "()" synatx instead of "yield"
def Evens_gen2(n):
''' a generator of evens up to n '''
return (num for num in range(n) if num%2==0)
# a generator which produces the **infinite** sequence of all positive even numbers
def All_evens_gen():
i=0
while True:
if i%2 == 0:
yield i
i+=2