How to refine list of directories to remove subdirectories of newly added directory
<p>I have a list of directories, eg:</p>

<pre><code>direc_list = [r'C:\test', r'C:\test2\subdir']
</code></pre>

<p>I then want to add another directory to the list </p>

<pre><code>new_direc = r'C:\test2'
</code></pre>

<p>How can I correctly remove any subdirectories of this new directory in my list?</p>

<p>After adding <code>r'C:\test2'</code> my output should be so that </p>

<pre><code>direc_list
&gt;&gt;&gt; [r'C:\test', r'C:\test2']
</code></pre>

<p>I was trying this using the <code>in</code> operator, </p>

<pre><code>for direc in direc_list:        
    if new_direc in direc:
        direc_list.remove(direc)
</code></pre>

<p>but this fails because the word 'test' is a substring of 'test2'</p>
