Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is to respond to the modifications you made to <code>sort_keyratios()</code> in the answer you posted to your own question. It's also so you have something else to up-vote, should you find the additional information useful. &lt;hint&gt;</p> <p>Anyway, you could do what is being done <em>much</em> more efficiently by building a dictionary that maps each <code>datacode</code> to a <code>(row, col)</code> pair once, and then just using this previously built table to look up the values in the function. TO facilitate that I've added a new function called <code>create_datacode_map()</code>.</p> <p>Here's how it could be used:</p> <pre><code>def create_datacode_map(): """ Create dictionary mapping datacodes to (row, col) in data. """ # define rows that have no useful data skip_list = {16, 17, 18, 28, 29, 38, 39, 40, 41, 46, 51, 56, 61, 62, 63, 69, 70, 71, 92, 93, 98, 99, 100} def find_row_col(datacode): skipped = 0 # match datacode to row, column for row in xrange(0, 109): if row in skip_list: skipped += 11 continue for col in xrange(0, 12): if datacode == col + (11*row) - skipped: return row, col # create and return the dictionary return {datacode: find_row_col(datacode) for datacode in xrange(1, 910)} def sort_keyratios(self, datacode): # convert datacode to row, column and return data in that position of list if not hasattr(self, 'datacode_map'): self.datacode_map = create_datacode_map() row, col = self.datacode_map[datacode] # lookup conversion return self.data[row][col] </code></pre> <p>The version of <code>sort_keyratios()</code> shown checks for the existence of <code>self.datacode_map</code> each time it's called and creates it if it doesn't exist. It would be more efficient to have done that already in <code>fetch_keyratios(()</code> so <code>sort_keyratios()</code> could assume it exists and not have to check each time it's called.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload