Determining if a query is in a string
<p>I have a list of query terms, each with a boolean operator associated with them, like, say:</p>

<pre><code>tom OR jerry OR desperate AND dan OR mickey AND mouse
</code></pre>

<p>Okay, now I have a string containing user-defined input, <code>inputStr</code>.</p>

<p>My question is, in Python, is there a way to determine if the string defined by the user contains the words in the "query"?</p>

<p>I have tried this:</p>

<pre><code>if ('tom' or 'jerry' or 'desperate' and 'dan' or 'mickey' and 'mouse') in "cartoon dan character desperate":
    print "in string"
</code></pre>

<p>But it doesn't give the output i expect.
As you can see, I don't care about whether the query terms are ordered; just whether they are in the string or not.</p>

<p>Can this be done? Am I missing something like a library which can help me achieve the required functionality?</p>

<p>Many thanks for any help.</p>
