I'm coding a to-do list program in Python. I created a Class named Calendar and a instance of it named calendar. This instance contains lists of the tasks, being the main list and the filtered lists.
Each item in the list is a task. Each task is a dictionary with its keys such as name, description, status, due date, etc.
I need to write a function that removes all the tasks from the main list that has its status as 'Completed'.
I wrote this, but the problem is that it removes only one completed task, instead of all of them.
def remove_completed():
for task in calendar.lista_main:
if task['status'] == 'Completed':
calendar.main_list.remove(task)
Thank you very much!
Edit: question was closed because it was already answered, but the answered questions is only about removing multiple instances of lists of values. The solutions didn't help me with this list of dicts, where you have to access keys and values.