Your task is to implement an efficient data structure for keeping a task list. You can add a new task with a name and a priority to the list, and you can extract the highest priority task from the list.
You may assume that the name of a task consists of the characters a
–z
and 0
–9
and that the priority is an integer in the range 0 \dots 10^9. The highest numeric value has the highest priority.
In a file tasks.py
, implement a class Tasks
with the following functions:
add
: add to the list a task with a given name and prioritynext
: delete the highest priority task from the list and return its name (if multiple tasks have the same priority, choose the one with the alphabetically smallest name)
Both functions must be efficient.
class Tasks: def add(self, name, priority): # TODO def next(self): # TODO 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