Files
RustPython/tests/snippets/generators.py
2018-10-27 17:05:22 +02:00

38 lines
472 B
Python

r = []
def make_numbers():
yield 1
yield 2
r.append(42)
yield 3
for a in make_numbers():
r.append(a)
assert r == [1, 2, 42, 3]
r = list(x for x in [1, 2, 3])
assert r == [1, 2, 3]
def g2(x):
x = yield x
yield x + 5
yield x + 7
i = g2(23)
assert 23 == next(i)
assert 15 == i.send(10)
assert 17 == i.send(10)
def g3():
yield 23
yield from make_numbers()
yield 44
r = list(g3())
# print(r)
assert r == [23, 1, 2, 3, 44]