PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from math import pi
from itertools import takewhile
# generates n*x, with x increasing by 0.1 each time
def dull(n):
x=0
while True:
yield n*x
x+= 0.1
gennie = dull(2)
# now it turns out that what you really want is values that are less than 1, when divided by pi, and you can't be bothered to change the generator:
mapped = map(lambda x: x/pi, gennie)
# mapping is more of a "converter", than a "creator"
print('My dream list:')
print(list(takewhile(lambda x: x < 1, mapped)))
# DON'T DO THIS (or maybe try it just once...):
#print([x/pi for x in gennie if x < pi])
# and this is OK:
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run