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>This appears functionality equivalent to:</p>

<pre><code>for i, char in enumerate(str2):
    if char in str1:
        # do something here
</code></pre>

<p><code>filter</code> is taking a list of tuples consisting of the index and elements of <code>str2</code>, filtering out those elements that do not appear in <code>str1</code>, then returning a iterable of the remaining indices and elements from <code>str2</code>.</p>

python lambda filter