Skip to content

Instantly share code, notes, and snippets.

@mdamien
Created March 1, 2019 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdamien/eb82e7042481c0a180f3fddb70d28504 to your computer and use it in GitHub Desktop.
Save mdamien/eb82e7042481c0a180f3fddb70d28504 to your computer and use it in GitHub Desktop.
liquid_democracy demo
from collections import Counter
users = [1, 2, 3, 4, 5, 6, 7, 8]
delegs = {
4: 1,
5: 2,
6: 3,
7: 5,
8: 5,
}
votes = {
1: 'A',
7: 'B',
5: 'C',
6: 'C',
}
def compute_vote(user):
if user in votes:
return votes[user]
if user in delegs:
return compute_vote(delegs[user])
return 'abst'
result = Counter([compute_vote(user) for user in users])
for choice, n, in result.most_common():
print(choice, n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment