mirror of
https://github.com/iritmaximus/tira.git
synced 2026-10-12 19:13:47 +03:00
44 lines
1.1 KiB
Plaintext
44 lines
1.1 KiB
Plaintext
from heapq import heappush, heappop
|
|
|
|
|
|
class Tasks:
|
|
def __init__(self):
|
|
self.dict = {}
|
|
self.priorities = []
|
|
|
|
def add(self, name, priority):
|
|
if self.dict.get(priority) is None:
|
|
self.dict[priority] = []
|
|
heappush(self.dict[priority], name)
|
|
else:
|
|
self.dict[priority].append(name)
|
|
|
|
heappush(self.priorities, -1 * priority)
|
|
print(self.priorities, self.dict)
|
|
|
|
def next(self):
|
|
highest_prio = self.priorities[0] * -1
|
|
top_prio_items = self.dict.get(highest_prio)
|
|
print(top_prio_items)
|
|
|
|
if len(top_prio_items) > 1:
|
|
highest_string = ""
|
|
for x in top_prio_items:
|
|
if x >= highest_string:
|
|
highest_string = x
|
|
else:
|
|
return top_prio_items[0]
|
|
|
|
return highest_string
|
|
|
|
|
|
if __name__ == "__main__":
|
|
t = Tasks()
|
|
t.add("siivous", 10)
|
|
t.add("ulkoilu", 50)
|
|
t.add("opiskelu", 50)
|
|
print(t.next()) # opiskelu
|
|
t.add("treffit", 100)
|
|
print(t.next()) # treffit
|
|
print(t.next()) # ulkoilu
|