Python any() function within a list comprehension
list-comprehension, python
Solution
Include the `in x` in the `any()`:
urlsIwant = [x for x in allurls if any(w in x for w in words)]
Problem
I'm new to Python (2 weeks!) and struggling with the following: I have a list of URLs that I want to iterate through and find just certain URLs. To do this I want to test any members of a tuple are present in the URL. I've figured out I need a any() statement but can't get the syntax right: ``` allurls = [<big list of URLs>] words = ('bob', 'fred', 'tom') urlsIwant = [x for x in allurls if any(w for w in words) in x] ``` gets me ``` TypeError: 'in <string>' requires string as left operand, not bool ``` I don't think it's relevant but my actual code is ``` urlsIwant = sorted(set([x for x in allurls if dict['value'] in x and any(w for w in words) in x])) ```