AT
У меня просто и мысли не было засунуть yield в списковые включения
Size: a a a
AT
АП
SF
M
yield
can be used in generator expressions and comprehensions:[(yield i) for i in 'ab']
# <generator object <listcomp> at 0x7f2ba1431f48>
list([(yield i) for i in 'ab'])
# ['a', 'b']
list((yield i) for i in 'ab')
# ['a', None, 'b', None]
yield
can be used in any function (turning it into a generator) and comprehensions are compiled into functions:>>> dis.dis("[(yield i) for i in range(3)]")
0 LOAD_CONST 0 (<code object <listcomp> ...>)
2 LOAD_CONST 1 ('<listcomp>')
4 MAKE_FUNCTION 0
...
SyntaxError
in python 3.8+. However, yield
inside lambda
still can be used:a = lambda x: (yield x)
list(a(1))
# [1]
AK
M
AK
AT
AT
M
M
M
AT
AT
M
AB
AB
AB