python deque/list filtering
<p>I have from a database, a list of actions. This is copied into a deque since I want to deal with it in order, popping stuff off the left as I go.</p>

<p>So I have something like actions = deque(actions) which is fine.</p>

<p>Each action item is a list from psycpg using the DictCursor. Each list has the item 'phase'.</p>

<p>So things go in phases. Some actions are in phase 'a', some in phase 'b', etc. Not the best way to store the data but that's what I got given.</p>

<p>So to make my life easier I want to split the deque into several deques by phase.</p>

<p>so if actions[0]['phase'] == 'a' then this goes in a list containing only items from phase a, and so on with, b, etc.</p>

<p>I could do this with a bunch of ifs and appending but that seems like a lot of effort. I think the answer might be filter(), but I'm not so sure how to use it.</p>

<p>Random stuff to note:</p>

<ul>
<li>Each item is in order, the order needs preserving within each deque.</li>
<li>The phases are known and sequential. For example, if phase c doesn't exist, we know that phase d doesn't exist. There are a finite number of phases, something like 5 if I recall.</li>
</ul>

<p>Clarification attempt:</p>

<p>I have a deque, actions. something like:</p>

<pre><code>actions = [
    ['phase': 'a', 'something_else': 'x'], 
    ['phase': 'a', 'something_else': 'y'],
    ['phase': 'b', 'something_else': 'x']
]
</code></pre>

<p>Want to end up with (something like):</p>

<pre><code>a = [
    ['phase': 'a', 'something_else': 'x'], 
    ['phase': 'a', 'something_else': 'y']
]
b = [
    ['phase': 'b', 'something_else': 'x']
]
</code></pre>

<p>With the mimimal amount of code, and something that works for any number of phases/items in phases/etc.</p>
