<commit_before>from collections import Counter
from random import randrange

class Game:
    def __init__(self, maxNum=9, numSecrets=4):
        self._numSecrets = numSecrets
        self._maxNum = maxNum
        self._secret = self._genSecret()

    def _genSecret(self):
        return [randrange(0, self._maxNum + 1)
                for _ in range(self._numSecrets + 1)]

    def guess(self, guess):
        # Returns (exact, inexact)
        exact = 0
        secret = self._secret[::]
        for i, (g, s) in enumerate(zip(guess[::], self._secret)):
            if g != s: continue
            # Well, we are kinda modifying lists as we go through them
            # which is generally a bad idea...
            secret.pop(i - exact)
            guess.pop(i - exact)
            exact += 1

        secretCount = Counter(secret)

        inexact = 0
        for g in guess:
            if secretCount[g] > 0:
                secretCount[g] -= 1
                inexact += 1
        return exact, inexact<commit_msg>Nicer code<commit_after>from collections import Counter
from random import randrange

class Game:
    def __init__(self, maxNum=9, numSecrets=4):
        self._numSecrets = numSecrets
        self._maxNum = maxNum
        self._secret = self._genSecret()

    def _genSecret(self):
        return [randrange(0, self._maxNum + 1)
                for _ in range(self._numSecrets + 1)]

    def guess(self, guess):
        # Returns (exact, inexact)
        exact = 0
        secret = self._secret[::]
        for i, (g, s) in enumerate(zip(guess[::], self._secret)):
            if g != s: continue
            # Well, we are kinda modifying lists as we go through them
            # which is generally a bad idea...
            secret.pop(i - exact)
            guess.pop(i - exact)
            exact += 1

        secretCount = Counter(secret)
        guessCount = Counter(guess)

        inexact = sum(min(guessCount[k], secretCount[k]) for k in guessCount)
        return exact, inexact
{'fraction_non_alphanumeric': 0.09905425584868094, 'fraction_numerical': 0.008959681433549029, 'mean_word_length': 1.8920863309352518, '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': '6907638', 'n_tokens_mistral': 610, 'n_tokens_neox': 573, 'n_words': 180}