Is is possible to break in lambda when the expected result is found
<p>I am Python newbie, and just become very interested in Lambda expression. The problem I have is to find one and only one target element from a list of elements with lambda filter. In theory, when the target element is found there is no sense to continue anymore. </p>

<p>With <code>for loop</code> it is pretty simple to <code>break</code> the loop, but what about by using <code>lambda</code>? is it after all possible to do this? I search from Google, but did not find the expected solution  </p>

<p>with just lambdas is no possible, you need either use <a href="https://docs.python.org/3/library/functions.html#filter" rel="nofollow"><code>filter</code></a> (<a href="https://docs.python.org/2/library/itertools.html#itertools.ifilter" rel="nofollow"><code>itertools.ifilter</code></a> in python 2) or a conditional generation expression, and call <a href="https://docs.python.org/3/library/functions.html#next" rel="nofollow"><code>next</code></a> on that one to get the first element out of it  </p>

<p>For example, let said you want the multiple of 5 in a list</p>

<pre><code>&gt;&gt;&gt; test=[1,2,3,6,58,78,50,65,36,79,100]
&gt;&gt;&gt; next( filter(lambda x:x%5==0,test) )
50
&gt;&gt;&gt; next( x for x in test if x%5==0 )
50
&gt;&gt;&gt;     
</code></pre>

python loops lambda