Match similar item in list
<p>I have 2 lists of hostnames</p>

<pre><code>foo=['some-router-1', 'some-switch-1', 'some-switch-2']

bar=['some-router-1-lo','some-switch-1','some-switch-2-mgmt','some-switch-3-mgmt']
</code></pre>

<p>I would expect output to be like...</p>

<pre><code>out=['some-switch-3-mgmt']
</code></pre>

<p>I want to find entries in <code>bar</code> that are not in <code>foo</code>. However some names in <code>bar</code> have <code>"-mgmt"</code> or some other string appended that don't occur in <code>foo</code>. The length and number of dashes per list item vary greatly, so I'm not sure how successful using a regex would be. I'm new to programming, so please provide some explanation if possible.</p>

<p>You can use <code>startswith()</code> to see if a string starts with another string. So something like:</p>

<pre><code>out = [bar_string for bar_string in bar if not bar_string.startswith(tuple(foo))]
</code></pre>

python list