Python

collections (Counter, defaultdict, deque)

Në shqip: Moduli collections

ShpjegimiSQ

Moduli collections ka struktura të dobishme: Counter numëron sa herë shfaqet çdo gjë, defaultdict krijon vetë vlerën kur çelësi mungon, deque është radhë e shpejtë nga të dy anët, namedtuple është tuple me emra.

EnglishEN

The collections module has handy structures: Counter counts how often each thing appears, defaultdict creates a value when a key is missing, deque is a fast double-ended queue, namedtuple is a tuple with names.

Si ta mendosh

Counter është si numërimi i votave në zgjedhjet e klasës.

Lexoje në anglisht

Counter is like counting votes in a class election.

Shembull kodipython

from collections import Counter
votat = ["Arta", "Dren", "Arta", "Ilir", "Arta"]
print(Counter(votat).most_common(1))   # [('Arta', 3)]

Terma të lidhur