Multi-column table sort with custom ordering for each column
<p>I have a multi-column table of data, each row unique, and I want to know how to sort it based on multiple columns. If sorting alphabetically a solution is already described <a href="http://www.saltycrane.com/blog/2007/12/how-to-sort-table-by-columns-in-python/" rel="nofollow">here</a>. However, instead of alphabetical sorting, I need to sort each column based on a custom ordering stored in another list. For example, if my table is</p>

<pre><code>mytable = [
    ('A1', 'B1', 'C1'),
    ('A1', 'B2', 'C2'),
    ('A2', 'B2', 'C1'),
    ('A2', 'B2', 'C2')
]
</code></pre>

<p>I might want the first column to be ordered ['A2','A1'], the second column to be ordered ['B1','B2'], and the third column to be ordered ['C2','C1']. The proper result would be</p>

<pre><code>mytable = [
    ('A2', 'B2', 'C2'),
    ('A2', 'B2', 'C1'),
    ('A1', 'B1', 'C1'),
    ('A1', 'B2', 'C2')
]
</code></pre>
