combine if filter terms from list

Rory Schramm etfeet at gmail.com
Fri Apr 21 20:17:04 EDT 2017


Hi,

I'm trying to use python list comprehensions to combine multiple terms for
use by a for loop if condition.


filters = [ 'one', 'two', 'three']
for line in other_list:
    if ' and '.join([item for item in filters]) not in line[2]:
        print line

The list comp returns  one and two and three and ..

The problem I'm having is the for loop isn't filtering out the terms from
the filter list. I suspect the problem is the if condition is treating the
results for the list comprehension as a literal string and not part of the
if condition itself. I'm not sure how to fix this though.

Any ideas on How to make this work?

Thanks!,

Rory



More information about the Python-list mailing list