from collections import Counter import heapq pogostosti = Counter( znak for znak in open("martin.txt").read().lower() if "a" <= znak <= "z" or znak in "čšž ") class Vozlisce: def __init__(self, znak, pogostost, levi=None, desni=None): self.znak = znak self.pogostost = pogostost self.levi = levi self.desni = desni def __repr__(self): return f"{self.znak} ({self.pogostost})" def __lt__(self, other): return self.pogostost < other.pogostost vozlisca = [Vozlisce(znak, pogostost) for znak, pogostost in pogostosti.items()] heapq.heapify(vozlisca)