comparing strings in list to strings in list
<p>I see that the code below can check if a word is </p>

<pre><code>list1 = 'this'
compSet = [ 'this','that','thing' ]
if any(list1 in s for s in compSet): print(list1)
</code></pre>

<p>Now I want to check if a word in a list is in some other list as below:</p>

<pre><code>list1 = ['this', 'and', 'that' ]
compSet = [ 'check','that','thing' ]
</code></pre>

<p>What's the best way to check if words in list1 are in compSet, and doing something over non-existing elements, e.g., appending 'and' to compSet or deleting 'and' from list1?</p>

<p>__________________update___________________</p>

<p>I just found that doing the same thing is not working with sys.path. The code below sometimes works to add the path to sys.path, and sometimes not.</p>

<pre><code>myPath = '/some/my path/is here'
if not any( myPath in s for s in sys.path):
    sys.path.insert(0, myPath)
</code></pre>

<p>Why is this not working? Also, if I want to do the same operation on a set of my paths,   </p>

<pre><code>myPaths = [ '/some/my path/is here', '/some/my path2/is here' ...]
</code></pre>

<p>How can I do it?</p>

<p>Try that:</p>

<pre><code> &gt;&gt;&gt; l = list(set(list1)-set(compSet))
 &gt;&gt;&gt; l
 ['this', 'and']
</code></pre>

python list