With the deadline of the final project creeping closer and closer, an I2P student has completely lost track of what he needs to do. Help him build a simple todo list to keep track of the tasks he needs to complete for this class. ( ̄^ ̄ )ゞ

What You Must Implement
Implement the following:
PendingTaskIterator.__init__
ADD or DONE operations on the TaskQueue must not affect an already-created PendingTaskIterator.PendingTaskIterator.__next__
TaskQueue.StopIteration when there are no more pending tasks.TaskQueue.add_task
"name" and "done": False to the underlying list.TaskQueue.mark_done
"name" equals name and whose "done" is False, and set that task’s "done" to True. If there is no pending task with that name, do nothing.TaskQueue.__iter__
PendingTaskIterator instance for this TaskQueue instead of the default list iterator.Code Template
class PendingTaskIterator:
def __init__(self, task_queue):
self.pending = []
self.index = 0
# TODO: fill self.pending with the pending tasks in the correct order
def __next__(self):
# TODO:
raise NotImplementedError
class TaskQueue(list):
def add_task(self, name):
# TODO:
# Append a new task dict to the list.
raise NotImplementedError
def mark_done(self, name):
# TODO:
# Traverse the underlying list in insertion order
raise NotImplementedError
def __iter__(self):
# TODO:
# Return a PendingTaskIterator for this TaskQueue
raise NotImplementedError
""" Do not change the code below """
q = int(input())
tq = TaskQueue()
for _ in range(q):
op = input().split()
if op[0] == "ADD":
name = " ".join(op[1:])
tq.add_task(name)
elif op[0] == "DONE":
name = " ".join(op[1:])
tq.mark_done(name)
elif op[0] == "LEN":
print(len(tq))
elif op[0] == "PRINTALL":
print(tq)
elif op[0] == "PENDING":
k = int(op[1])
it = iter(tq)
for _ in range(k):
print(next(it))
Test cases:
q: the number of operations.q lines is one of:
for task in self: here, because that will use the overridden iterator.k of them.Constraints:
1 ≤ q ≤ 1000
0 ≤ k ≤ current_number_of_pending_tasks
For each following operation, output the corresponding text:
k pending tasks.