<commit_before>from pyseeyou.cldr_rules import cardinals

def lookup_closest_locale(locale, available, separator = '_'):
    '''
    Looks up the closest available locale to use for specified locale

        :param locale: BCP 47 language tag to lookup
        :param available: Dictionary or list with available locales
        :param separator: Language tag extensions separator

        :returns: Best available candidate to use
    '''
    if isinstance(locale, str) and locale in available:
        return locale

    locales = []
    if isinstance(locale, list):
        locales = [] + locale
    else:
        locales.append(locale)

    for i in range(len(locales)):
        current = locales[i].split(separator)
        while len(current) != 0:
            candidate = separator.join(current)
            if candidate in available:
                return candidate

            current.pop()

def get_cardinal_category(num_string, locale):
    n, i, v, w, f, t = get_parts_of_num(num_string)

    closest_locale = lookup_closest_locale(locale, cardinals)

    if not closest_locale:
        closest_locale = 'en'<commit_msg>Use 'pythonic' for loop over locales<commit_after>from pyseeyou.cldr_rules import cardinals

def lookup_closest_locale(locale, available, separator = '_'):
    '''
    Looks up the closest available locale to use for specified locale

        :param locale: BCP 47 language tag to lookup
        :param available: Dictionary or list with available locales
        :param separator: Language tag extensions separator

        :returns: Best available candidate to use
    '''
    if isinstance(locale, str) and locale in available:
        return locale

    locales = []
    if isinstance(locale, list):
        locales = [] + locale
    else:
        locales.append(locale)

    for locale in locales:
        current = locales[locale].split(separator)
        while len(current) != 0:
            candidate = separator.join(current)
            if candidate in available:
                return candidate

            current.pop()

def get_cardinal_category(num_string, locale):
    n, i, v, w, f, t = get_parts_of_num(num_string)

    closest_locale = lookup_closest_locale(locale, cardinals)

    if not closest_locale:
        closest_locale = 'en'
{'fraction_non_alphanumeric': 0.07695671184958461, 'fraction_numerical': 0.0026235242675994755, 'mean_word_length': 2.726384364820847, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6018404', 'n_tokens_mistral': 634, 'n_tokens_neox': 608, 'n_words': 204}