import wikipediaapi def get_all_titles_from_category(category: str) -> list: wiki = wikipediaapi.Wikipedia("ru") cat = wiki.page(category) names = [c.title() for c in cat.categorymembers] return names def get_count_list_by_first_letter(names: list) -> dict: names_dict: dict = {} for n in names: first_letter = n[0] count = names_dict.get(first_letter, 0) names_dict[first_letter] = count + 1 return names_dict def main(): wiki = wikipediaapi.Wikipedia("ru") animals = get_all_titles_from_category("Категория:Животные по алфавиту") # animals = get_all_titles_from_category("Категория:Знаменитые животные по алфавиту") result: dict = get_count_list_by_first_letter(animals) for names, count in result.items(): print(f"{names}: {count}") if __name__ == "__main__": main()