Modify your code in this way:
keyword_list=['WASHER', 'SCREW']
all_text = "test_string"
print any # so we can see where it comes from
mkgen = lambda: (word in all_text for word in keyword_list)
print list(mkgen()) # to see what we have
if any(mkgen()):
print "any: some of the strings found in str"
else:
print "any: no strings found in str"
if (True in mkgen()):
print "in: some of the strings found in str"
else:
print "in: no strings found in str"
This program makes it apparent what happens:
- it prints out the nature of
any
so you see if it is the "normal one" or a version overwritten by someimport *
- it as well prints out the boolean values generated
If you have managed to find out what's wrong, please use the any()
variant. It is much more pythonic.