Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've had a look at your code, and it looks like you make a lot of function calls and attribute lookups as part of your 'checking' or looking ahead before leaping. You also have a lot of code dedicated to track the same condition, i.e many bits of code looking at creating 'unique' IDs. </p> <p>instead of trying to assign some kind of unique string to each ballot, couldn't you just use the ballotID (an integer number?)</p> <p>now you could have a dictionary (uniqueBallotIDs) mapping ballotID and the actual ballot object.</p> <p>the process might be something like this:</p> <pre><code>def appendBallot(self, ballot, ballotID=None): if ballotID is None: ballotID = self._getuniqueid() # maybe just has a counter? up to you. # check to see if we have seen this ballot before. if not self._isunique(ballotID): # code for non-unique ballot ids. else: # code for unique ballot ids. self.ballotOrder.append(i) </code></pre> <p>You might be able to handle some of your worries about the dictionary missing a given key by using a defaultdict (from the collections module). <a href="http://docs.python.org/library/collections.html" rel="nofollow noreferrer">collection docs</a></p> <p><strong>Edit</strong> for completeness I will include a sample usage of the defaultdict:</p> <pre><code>&gt;&gt;&gt; from collections import defaultdict &gt;&gt;&gt; ballotIDmap = defaultdict(list) &gt;&gt;&gt; ballotID, ballot = 1, object() # some nominal ballotID and object. &gt;&gt;&gt; # I will now try to save my ballotID. &gt;&gt;&gt; ballotIDmap[ballotID].append(ballot) &gt;&gt;&gt; ballotIDmap.items() [(1, [&lt;object object at 0x009BB950&gt;])] </code></pre>
    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.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    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