Passing a function with two arguments to filter() in python
<p>Given the following list:</p>

<pre><code>DNA_list = ['ATAT', 'GTGTACGT', 'AAAAGGTT']
</code></pre>

<p>I want to filter strings longer than 3 characters. I achieve this with the following code:</p>

<p>With for loop:</p>

<pre><code>long_dna = []
for element in DNA_list:
    length = len(element)
    if int(length) &gt; 3:
        long_dna.append(element)
print long_dna
</code></pre>

<p>But I want my code to be more general, so I can later filter strings of any length, so I use a function and for loop:</p>

<pre><code>def get_long(dna_seq, threshold):
    return len(dna_seq) &gt; threshold

long_dna_loop2 = []
for element in DNA_list:
    if get_long(element, 3) is True:
        long_dna_loop2.append(element)
print long_dna_loop2
</code></pre>

<p>I want to achieve the same generality using <code>filter()</code> but I cannot achieve this. If I use the above function <code>get_long()</code>, I simply cannot pass arguments to it when I use it with <code>filter()</code>. Is it just not possible or is there a way around it?</p>

<p>My code with <code>filter()</code> for the specific case:</p>

<pre><code>def is_long(dna):
        return len(dna) &gt; 3

    long_dna_filter = filter(is_long, DNA_list)
</code></pre>