How can I find and remove elements that have a specific pattern from a list?
<p>I have a list that is something like this:</p>

<pre><code>output=['Filesystem            Size  Used Avail Use% Mounted on', '/dev/mapper/vg00-lvol_root', '                      976M  356M  570M  39% /', 'tmpfs                 1.9G     0  1.9G   0% /dev/shm', '/dev/mapper/vg00-lvol_apps', '                       20G  6.1G   13G  33% /apps', '/dev/sda1             976M   63M  863M   7% /boot', '/dev/mapper/vg00-lvol_data'.....]
</code></pre>

<p>I want to remove all the elements that has the format <code>"/dev/mapper/...."</code>.
E.g. here <code>list[1]='/dev/mapper/vg00-lvol_root'</code>. I tried using the index to remove(since in this case the odd no is occupied by the pattern. But that's not the case always). I then tried the logic of converting the elements to strings and then use regex to find the pattern. I thought of running a for loop to extract the list elements to individual strings(all that was complicated). I'm sure there must be an easier way to solve this</p>

<p>if you have multiple strings need to be check, you may need this.</p>

<pre><code>regex=re.compile('^/dev/mapper|^/usr/a')
filtered_list = [s for s in my_list if not re.match(regex, s)]
</code></pre>

python python-2.7 python-3.x