python code with lambda and filter
<p>Can anyone help me understand the following piece of python code:</p>

<pre><code>for i, char in filter(lambda x: x[1] in str1, enumerate(str2)):
    # do something here ...
</code></pre>

<p>str1 and str2 are strings, I sort of understand that the "lambda x: x[1] in str1" is filtering condition, but why x[1] ?</p>

<p>How can I convert this for loop into a lower level (but easier to understand) python code ?</p>

<p>Thanks</p>

<p>Because of <code>enumerates</code>.</p>

<p>Enumerates returns tuples of <code>(index, value)</code> for an iterable of values.</p>

<p><code>x</code> is a tuple of index, char.</p>

<p>I would write <code>lambda (index, char): char in str1</code> for clarity</p>

python lambda filter