Search for a partial string in an array of strings
<p>What is the Pythonic/quick way to search for a partial string in an array and then remove that string from the array?<br>
(I can do it with a simple loop and IF IN and rebuild two array in the loop, Asking if there is a Pythonic way/function to do this)</p>

<p>Example:  </p>

<pre><code>array = ['rule1','rule2','exception[type_a]','rule3','exception[type_b]']
res(,)=remove_exceptions(array,'exception')
print(res[0]) &gt;&gt;&gt; ['rule1','rule2','rule3']
print(res[1]) &gt;&gt;&gt; ['exception[type_a]','exception[type_b]']
</code></pre>

<p>Seriously, just use a <code>for</code> loop, you're trying to create <em>two</em> lists so a single comprehension won't do (i.e the top solution so far iterates <em>twice</em> over the same list).</p>

<p>Create two lists and append to them conditionally:</p>

<pre><code>l1 = list()
l2 = list()
for i in array:
    l1.append(i) if 'exception' in i else l2.append(i)

print(l1)
['exception[type_a]', 'exception[type_b]']
print(l2)
['rule1', 'rule2', 'rule3']
</code></pre>

python arrays python-3.x