python: lambda, yield-statement/expression and loops (Clarify)
<p><strong>TL;DR:</strong>  Can we implement <code>yield</code> or generator statement (with a loop) within a <code>lambda</code>? </p>

<p>My question is to clarify:</p>

<p>Whether the following simple loop function can be implemented with yield</p>

<pre><code>def loopyield():
   for x in range(0,15):
      yield x
print(*loopyield())
</code></pre>

<p>Results in error:</p>

<pre><code>lamyield=lambda x: yield x for x in range(0,15)
                       ^
SyntaxError: invalid syntax
</code></pre>

<p>Which looks like, it was expecting something as right operand for unwritten return statement but found the <code>yield</code> and getting confused.</p>

<p>Is there a proper legit way to achieve this in a loop? </p>

<p>Side note: <code>yield</code> can be statement/expression depending on who you ask: <a href="https://stackoverflow.com/questions/20142450/yield-statement-or-expression">yield - statement or expression?</a></p>

<p><strong>Final Answer :</strong> yield can be used with lambda but the limitation(single-line) makes it useless.  <code>for/while</code> not possible in lambda because they are not expressions.  <em>-user2357112</em> implicit for loop is possible with list comprehension, and yield is valid within the list comprehension. -<em>wim</em></p>

<p><strong>Verdict-</strong> Explicit loops not possible because lambdas in python can only contain expressions, and to write an explicit loop you will need to use statements. <em>-wim</em></p>