<commit_before>"Calculate distribution using D'Hondt"


def dhondt(votes_cast, total_seats):
    seats_per_party = dict.fromkeys(votes_cast.keys(), 0)
    quotients = [(votes, 0, party) for party, votes in votes_cast.iteritems()]
    for seat in range(total_seats):
        print("%s %s" % (seat, quotients))
        round_winner = max(quotients)
        idx = quotients.index(round_winner)
        max_quotient, inv_seats, party = round_winner
        seats_per_party[party] += 1
        quotients[idx] = votes_cast[party] / (seats_per_party[party] + 1), inv_seats-1, party
    return seats_per_party


def test():
    partidos = ('A', 'B', 'C', 'D', 'E',)

    votos = (340000, 280000, 160000, 60000, 15000,)
    escanos = (3, 3, 1, 0, 0)

    data = dict(zip(partidos, votos))

    assert dhondt(dict(a=1), 1) == dict(a=1)
    assert dhondt(dict(a=2, b=1), 1) == dict(a=1, b=0)
    assert dhondt(dict(a=3, b=2, c=1), 2) == dict(a=1, b=1, c=0)
    assert dhondt(dict(a=10, b=4, c=1), 3) == dict(a=2, b=1, c=0)
    assert dhondt(data, 7) == dict(zip(partidos, escanos))


def test_cordoba():
    from collections import OrderedDict
    partidos = 'PSOE', 'PP', 'IU'
    votos = 246324, 166665, 47908
    escanos = 4, 3, 0

    data = OrderedDict(zip(partidos, votos))
    resultado = OrderedDict(zip(partidos, escanos))

    assert dhondt(data, 7) == resultado


def test_cordoba_dos():
    partidos = 'PSOE', 'PP', 'IU'
    votos = 246324-7647, 166665, 47908+7647
    escanos = 4, 2, 1

    data = dict(zip(partidos, votos))
    resultado = dict(zip(partidos, escanos))


    assert dhondt(data, 7) == resultado<commit_msg>Remove parties from dhondt function and simplify<commit_after>"Calculate distribution using D'Hondt"


def dhondt(votes_cast, total_seats):
    seats_per_party = [0] * len(votes_cast)
    quotients = zip(votes_cast, seats_per_party)
    for seat in range(total_seats):
        print("%s -> %s" % (seat, quotients))
        round_winner = max(quotients, key=lambda x: (x[0], -x[1]))
        idx = quotients.index(round_winner)
        seats_per_party[idx] += 1
        quotients[idx] = votes_cast[idx] / (seats_per_party[idx] + 1), seats_per_party[idx]
    return tuple(seats_per_party)


def test_basic():
    assert dhondt((1, ), 1) == (1, )
    assert dhondt((2, 1), 1) == (1, 0)
    assert dhondt((3, 2, 1), 2) == (1, 1, 0)
    assert dhondt((10, 4, 1), 3) == (2, 1, 0)


def test_wikipedia():
    votos = (340000, 280000, 160000, 60000, 15000,)
    escanos = (3, 3, 1, 0, 0)

    assert dhondt(votos, 7) == escanos


def test_cordoba():
    votos = 246324, 166665, 47908
    escanos = 4, 3, 0

    assert dhondt(votos, 7) == escanos


def test_cordoba_dos():
    votos = 246324-7647, 166665, 47908+7647
    escanos = 4, 2, 1

    assert dhondt(votos, 7) == escanos
{'fraction_non_alphanumeric': 0.15574650912996776, 'fraction_numerical': 0.08020050125313283, 'mean_word_length': 3.463258785942492, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1906863', 'n_tokens_mistral': 1301, 'n_tokens_neox': 1119, 'n_words': 268}