Skip to content Skip to sidebar Skip to footer

Need Help Printing List

I'm working on a todo list in Python and I am currently stuck on printing the todo list. I have my add code and view code as such: if sel == '1': #add task name = inpu

Solution 1:

Assuming view2(x) is the function for printing and x is the dictionary which you have mentioned in the question.

You can do something like this

defview2(x):
    for key, val in x.items():
        print("{0} - {1}".format(key, val))

Solution 2:

This code will work for any number of todos in the list.

todo_list = [{'test 1': 'low'}, {'test 2': 'low'}]
defshow(todo_list):
    for index, todo inenumerate(todo_list, start=1):
        for key in todo.keys(): 
            print(index, key, todo[key])

show(todo_list)

Post a Comment for "Need Help Printing List"