Create a Simple To-Do List Manager
Build a basic to-do list manager function that allows adding tasks, marking them as complete, and viewing remaining tasks.
Challenge prompt
Write a Python function called manage_todo_list that accepts two parameters: a list of current tasks (each task is a dictionary with keys 'task' and 'completed'), and a command dictionary with keys 'action' and optionally 'task'. The function should support three actions: 'add' to add a new task (provided in the command dictionary), 'complete' to mark an existing task as completed by its name, and 'view' to return a list of task names that are not yet completed. If an action is unrecognized, return the string 'Invalid action'.
Guidance
- • Use simple loops and conditionals to process the tasks list based on the command.
- • Make sure to handle cases where the task to complete may not exist.
- • Return the list of incomplete task names only for the 'view' action.
Hints
- • To mark a task complete, loop through the tasks to find the matching task name.
- • Remember that 'add' action requires a new task name in the command dictionary.
- • Return values should match the action: return updated tasks list for 'add' and 'complete', and a list of task names for 'view'.
Starter code
def manage_todo_list(tasks, command):
# Your code here
passExpected output
For input tasks = [{'task': 'buy milk', 'completed': False}], command = {'action': 'add', 'task': 'walk dog'} => returns [{'task': 'buy milk', 'completed': False}, {'task': 'walk dog', 'completed': False}] For command = {'action': 'complete', 'task': 'buy milk'} => returns [{'task': 'buy milk', 'completed': True}, {'task': 'walk dog', 'completed': False}] For command = {'action': 'view'} => returns ['walk dog']
Core concepts
Challenge a Friend
Send this duel to someone else and see if they can solve it.