Python: Detecting only specific string not it's variations for dictionary
<p>I am trying to take in all the files at a given path, and order them based on my data title names.
So my data title names are:</p>

<pre><code>data_titles = ['CPU','Physical_Disk','Memory','Network','Network#2']
</code></pre>

<p>The files at this given path are named like <code>'CPU_data.txt'</code> and <code>'Memory_data.txt'</code>, <code>'Network_data.txt'</code>,<code>'Network#2_data.txt'</code> etc.</p>

<p>I am trying to create a dicitonary in the style of:</p>

<pre><code>{'Network': 'Network_data.txt', 
 'Network#2': 'Network#2_data.txt', 
 'Physical_Disk': ['Physical_Disk_data_1.txt','Physical_Disk_data_2.txt'], 
 'CPU': 'CPU_data.txt', 
 'Memory': 'Memory_data.txt'}
</code></pre>

<p>However what I actual get is:</p>

<pre><code>{'Network': ['Network_data.txt','Network#2_data.txt'], 
 'Network#2': ['Network#2_data.txt'], 
 'Physical_Disk': ['Physical_Disk_data_1.txt','Physical_Disk_data_2.txt'], 
 'CPU': ['CPU_data.txt'], 
 'Memory': ['Memory_data.txt']}
</code></pre>

<p>Here is my code:    </p>

<pre><code>table_csv_files={}
    for file_names in os.listdir(Data_folder):
        for name in data_titles:
            if name in file_names:
                if name in table_csv_files:
                    table_csv_files[name].update(file_names)
                else:
                    table_csv_files[name]=[file_names]

                print table_csv_files
</code></pre>

<p>How to I ensure that for the data_title <code>'Network'</code> only <code>'Network_data.txt'</code> is detected not also <code>'Network#2_data.txt'</code></p>