 <p>Your problem is exacerbated by the datastructure you are using. Although it is suitable for printing, it is not especially good for performing the operation you want to perform.</p> <p>You need to use, or create a datastructure which supports row and column operations. You might like to use a <code>numpy</code> <code>array</code> to store this data, and then manipulate it with slicing operations.</p>