Extract subset from several file names using python
<p>I have a lot of files in a directory with name like:</p>

<p>'data_2000151_avg.txt', 'data_2000251_avg.txt', 'data_2003051_avg.txt'...</p>

<p>Assume that one of them is called fname. I would like to extract a subset from each like so:</p>

<pre><code>fname.split('_')[1][:4]
</code></pre>

<p>This will give as a result, 2000. I want to collect these from all the files in the directory and create a unique list. How do I do that?</p>