/
ilya.petrash
/
SimplePyScripts
Обзор
Документация
Войти
/
ilya.petrash
/
SimplePyScripts
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
find_most_common_substrings_in_a_string.py
31 строка
627 B
gil9red
Refactoring. Using black code style
24 июн 2023, 17:36
24 июн 2023, 17:36
c187450
Код
Авторство
О чём код?
#!/usr/bin/env python3 # -*- coding: utf-8 -*- __author__ = "ipetrash" from collections import defaultdict text = "ACGTTGCATGTCGCATGATGCATGAGAGCT" accumulator = defaultdict(int) for length in range(1, len(text) + 1): for start in range(len(text) - length): sub_text = text[start : start + length] accumulator[sub_text] += 1 print(accumulator) max_items = defaultdict(list) for k, v in accumulator.items(): max_items[v].append(k) print(max_items) # Находим ключ с максимальным значением max_key = max(max_items) print(max_key, max_items[max_key]) # 9 ['G']