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>If you want to separate your items you can do it with one loop and by preserving the items in a dictionary:</p>

<pre><code>&gt;&gt;&gt; d = {}
&gt;&gt;&gt; for i in array:
...     if 'exception' in i:
...         d.setdefault('exception', []).append(i)
...     else:
...         d.setdefault('other', []).append(i)
... 
&gt;&gt;&gt; 
&gt;&gt;&gt; d
{'exception': ['exception[type_a]', 'exception[type_b]'], 'other': ['rule1', 'rule2', 'rule3']}
</code></pre>

<p>You can access to separated items by calling the values of the dictionary:</p>

<pre><code>&gt;&gt;&gt; d.values()
[['exception[type_a]', 'exception[type_b]'], ['rule1', 'rule2', 'rule3']]
</code></pre>

python arrays python-3.x