bradbeattie / python-vote-core

Python libraries for various electoral methods
http://modernballots.com
Other
140 stars 36 forks source link

SchultzeMethod(), possibly others, rewrite the ballots argument (+ 2 solutions) #32

Closed ghost closed 7 years ago

ghost commented 7 years ago

Hey Brad et al,

I'm not sure if this is a bug but I thought it would be good to mention for anyone else who runs across it. I'm running py3votecore in Python 3.6.


When I run

SchulzeMethod( votes, ballot_notation=CondorcetHelper.BALLOT_NOTATION_GROUPING)

twice in a row, it fails the second time. You get back an AttributeError: 'dict' object has no attribute 'reverse' from standardize_ballots.

The reason: If you look at the votes argument, you'll see that it has been changed from the example-given ballot notation, which looks like

votes = [
  { "count":5, "ballot": [ ["A"], ["B"], ["fish"] ] },
   # ...
  ]

into [ {"count":5, "ballot": {'A':1, 'B':2, 'fish':3, 'love':0, ... } } ]. The format has been changed from BALLOT_NOTATION_GROUPING into the usual format for the program.

This is a result of how Python handles arguments - it's pass by reference, not pass by value. There are 2 ways to deal with this:


Sorry if this isn't issue worthy, it's just a quirk of the software I felt would be good to point out. Certainly tripped me up when I was learning it.

bradbeattie commented 7 years ago

python3 vote core isn't me. You might want to try https://github.com/eiriks/python3-vote.