for x in range(0,15):
lamyield=lambda x: yield x for x in range(0,15)
SyntaxError: invalid syntax
The one-liner you seem to be trying to create is actually technically possible with a lambda, you just need to help the parser a bit more:
>>> lamyield = lambda: [(yield x) for x in range(15)] >>> print(*lamyield()) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
This uses a for loop implicitly in a list comprehension. It is not possible with an explicit
while loop or
for loop outside of a comprehension. That's because lambdas in python can only contain expressions, and to write an explicit loop you will need to use statements.