diff --git a/apportionment.py b/apportionment.py index 03dfbda..68f3008 100644 --- a/apportionment.py +++ b/apportionment.py @@ -4,8 +4,8 @@ import math from fractions import Fraction -def method(method, votes, seats, parties=string.letters, threshold=None, - verbose=True): +def method(method, votes, seats, parties=string.ascii_letters, + threshold=None, verbose=True): filtered_votes = apply_threshold(votes, threshold) if method == "quota": return quota(filtered_votes, seats, parties, verbose) @@ -44,7 +44,8 @@ def __print_results(representatives, parties): # verifies whether a given assignment of representatives # is within quota -def within_quota(votes, representatives, parties=string.letters, verbose=True): +def within_quota(votes, representatives, parties=string.ascii_letters, + verbose=True): n = sum(votes) seats = sum(representatives) within = True @@ -67,7 +68,7 @@ def within_quota(votes, representatives, parties=string.letters, verbose=True): # Largest remainder method (Hamilton method) -def largest_remainder(votes, seats, parties=string.letters, +def largest_remainder(votes, seats, parties=string.ascii_letters, verbose=True): if verbose: print("\nLargest remainder method with Hare quota (Hamilton)") @@ -103,7 +104,7 @@ def largest_remainder(votes, seats, parties=string.letters, # Divisor methods -def divisor(votes, seats, method, parties=string.letters, +def divisor(votes, seats, method, parties=string.ascii_letters, verbose=True): representatives = [0] * len(votes) if method in ["dhondt", "jefferson", "greatestdivisors"]: @@ -216,7 +217,7 @@ def __divzero_fewerseatsthanparties(votes, seats, parties, verbose): # ( see Balinski, M. L., & Young, H. P. (1975). # The quota method of apportionment. # The American Mathematical Monthly, 82(7), 701-730.) -def quota(votes, seats, parties=string.letters, verbose=True): +def quota(votes, seats, parties=string.ascii_letters, verbose=True): if verbose: print("\nQuota method") representatives = [0] * len(votes) diff --git a/examples/nr_wahlen.txt b/examples/nr_wahlen.txt index 5cb0b10..478c482 100644 --- a/examples/nr_wahlen.txt +++ b/examples/nr_wahlen.txt @@ -1,6 +1,6 @@ (2019,["ÖVP", "SPÖ", "FPÖ", "NEOS", "JETZT", "GRÜNE", "KPÖ", "WANDL", "BZÖ", "BIER", "CPÖ", "GILT", "SLP"], [1789417, 1011868, 772666, 387124, 89169, 664055, 32736, 22168, 760, 4946, 260, 1767, 310], [71, 40, 31, 15, 0, 26, 0, 0, 0, 0, 0, 0, 0]) (2017, ["SPÖ", "ÖVP", "FPÖ", "GRÜNE", "NEOS", "PILZ", "GILT", "FLÖ", "KPÖ", "WEIßE", "SLP", "EUAUS", "M", "CPÖ", "NBZ", "ODP"], [1361746, 1595526, 1316442, 192638, 268518, 223543, 48234, 8889, 39689, 9167, 713, 693, 221, 425, 2724, 761], [52, 62, 51, 0, 10, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) -(2013, ["SPÖ", "ÖVP", "FPÖ","BZÖ", "GRÜNE", "FRANK", "NEOS", "KPÖ", "PIRAT", "CPÖ", "WANDL", "M", "EUAUS", "SLP"], [1258605, 1125876, 962313, 165746, 582657, 268679, 243946, 48175, 36265, 6647, 3051, 490, 510, 947], [52, 47, 40, 0, 24, 11, 9, 0, 0, 0, 0, 0, 0, 0]) +(2013, ["SPÖ", "ÖVP", "FPÖ","BZÖ", "GRÜNE", "FRANK", "NEOS", "KPÖ", "PIRAT", "CPÖ", "WANDL", "M", "EUAUS", "SLP"], [1258605, 1125876, 962313, 165746, 582657, 268679, 232946, 48175, 36265, 6647, 3051, 490, 510, 947], [52, 47, 40, 0, 24, 11, 9, 0, 0, 0, 0, 0, 0, 0]) (2008, ["SPÖ", "ÖVP", "GRÜNE", "FPÖ", "BZÖ", "FRITZ", "DC", "KPÖ", "LIF", "RETTÖ", "LINKE", "KLEMENTE", "LINKE", "STARK", "TRP"], [1430206, 1269656, 509936, 857029, 522933, 86194, 31080, 37362, 102249, 35718, 349, 347, 1789, 237, 2224], [57, 51, 20, 34, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) # LINKE = Die Linke und LINKE = Linke (2006, ["ÖVP", "SPÖ", "FPÖ", "GRÜNE", "BZÖ", "KPÖ", "MATIN", "NFÖ", "IVE", "STARK", "SAU", "SLP"], [1616493, 1663986, 519598, 520130, 193539, 47578, 131688, 10594, 592, 312, 1514, 2257], [66, 68, 21, 21, 7, 0, 0, 0, 0, 0, 0, 0]) (2002, ["SPÖ", "FPÖ", "ÖVP", "GRÜNE", "KPÖ", "LIF", "DD", "CWG", "SLP"], [1792499, 491328, 2076833, 454980, 27568, 48083, 2439, 2009, 3906], [69, 18, 79, 17, 0, 0, 0, 0, 0])