Day 045 - Project 45 : Prioritising ToDo List

If you have any questions, comments or issues with this project please post them here!

Hi there!

I find it weird that when editing a row, we actually remove and add a new one.

As we have identified the row we want to edit with this:

for row in todo:
    if find in row:

Cannot we simply define a new value for this same row by doing:

task = input("New task: ")
deadline = input("New deadline: ")
priority = input("New priority: ")
row = [task, deadline, priority]

Is there another way that doesn’t affect the row order while editing?

Hey! We answered your question on Replit 101 tonight as the first one up, example code is here https://replit.com/@DavidAtReplit/JitteryFatalConfigfiles and recording of the session is at Replit 101 Coding Helpline - YouTube

2 Likes

Oh many thanks @DavidAtReplit! That was simple, but it makes it much clearer to me!

I am stuck here… I decided to use dictionaries instead of dynamic lists (I dont know why, seemed to make more sense in my head as a tabular/spreadsheet format), and all was well, the hardest part is printing out specific priorities.

todoItem = {}
namelist = []
deadlinelist = []
prioritylist = []

def prettyPrint():
  print()
  for i in range(len(todoItem['namelist'])):
    print(f"{namelist[i]: <10} | {deadlinelist[i]: ^15} | {prioritylist[i]: >17} |")

def print_values(dictionary, key, value):
  for k, v in dictionary.items():
    if value in v[key]:
      print("trying to print the selected priorities")
      print(v)

(code here for the menu, navigation..)
..
      selection = input("Which priority would you like to view?\n (1) for HIGH priority \n (2) for MEDIUM priority \n (3) for LOW priority \n > ")
      selection = int(selection)
      print("let's try printing this")
      print_values(todoItem, 'priority', selection)

First I tried to enumarate and index all priorities (therefore coded pretty_print to be for such)… Then I changed priorirties to 1,2,3 (instead of high medium low)… Ideally print_values would print every line that has the selected key-value pair, but doesnt work…

Should I just scrap everything and go for nested lists?

I am not sure what i am over look or over thinking, i am trying to have it check if the task to edit is in the todo list before locating its exact position. Is this not the right way to go about it or did I overlook something. Here is the Edit function I made it keeps going straight to the else statement.

def editToDo ():
  os.system('clear')
  print("Edit: ")
  print()
  search = input("Which task are we editing? >")

  if search in toDos:
    for i in range(len(toDos)):
      if search in toDos[i]:
        task = input("What is the new task? > ")
        due = input("What is the new due date? > ")
        priority = input("What is the new priority? > ")
        edited = [task, due, priority]
        toDos[i] = edited
        print()
        print("Task has been edited.")
        time.sleep(1)
  else:
    print("That item is not in the To Do list. Returning to the menu.")

the item you are looking for is not just inside the list, but inside a row inside that list, because it is a 2d list.

the line if search in toDos: compares search to whole rows in toDos, not to single items inside rows, that’s why it keeps going to the else statement.

i think you can just remove the first if search in toDos: statement because you are later checking for search again with if search in toDos[i]:. and make the else statement part of that if statement.

1 Like

Hi guys!
please can you take a look at my code and let me know what you think as it looks completely different to davids in some areas! :crazy_face:
https://replit.com/@AndrewPlatt2/day-45-of-100-days-of-code-todolist?v=1
I think im overthinking the problems and doing more than is required because the solutions always seem a lot simplier than what i come up with
thanks!
andy

1 Like

i noticed that in your remove() and edit() subroutines you’re using range(len(to_do_list)) on both row and column. but the length of a list is only the number of rows, not columns. not an issue in this case because the item you’re looking for is in the first column. but if the item you’re looking for was in another column and there were fewer rows than columns this method would miss them. an alternative different from david’s solution is the way you did it in the priorityprint() subroutine.

but yea i too end up with longer and unnecessarily complicated code. i guess it’s a matter of practice and learning what exactly the syntax does so you don’t do unnecessary steps. i’ve certainly learned a few tricks from david’s solutions.

1 Like

there is some boolean logic used to solve problems where as till day 45 there is nothing taught about boolean

if found = true or false or some thingamajig

Dis not taught yet and I feel lost

Here is a w3schools link containing everything you need to know about booleans:

2 Likes

Trying to wrap my head around this bit of the solution:

def edit():
  time.sleep(1)
  os.system("clear")
  find = input("Name of todo to edit > ")
  found = False
  for row in todo:
    if find in row:
      found = True
  if not found:
    print("Couldn't find that")
    return
  for row in todo:
    if find in row:
      todo.remove(row)
  name = input("Name > ")
  date = input("Due Date > ")
  priority = input("Priority > ").capitalize()
  row = [name, date, priority]
  todo.append(row)
  print("Added")

firstly, I don’t really understand the found = False bit. Is this just a variable we made up just to look at if the task they want to edit, is in the list? I feel like I half understand, but it’s not what I would have thought of at all so feeling a bit out of my depth here.
secondly, could you not put the “todo.remove(row)” under the first “for row in todo:
if find in row:
found = True” bit? like

for row in todo:
    if find in row:
      found = True
      todo.remove(row)

Thanks! x

2 Likes

Hey @ahollyborealis , if I understand the code correctly, found is to check if the todo is present. if find in row checks if the todo is present in the todo list, so found is True. if not found basically means that if found==False.

2 Likes

I could not understand the subroutine for the view option. Couldn’t understand why we used a boolean and the logic behind the if statements. Please help me out.

See the post above by Nate. If you have any more questions, please send your code.

3 Likes

I have the same doubt. We could’ve put “todo.remove(row)” under the first “for row in todo:
if find in row:
found = True” bit.

Hi everyone!

In my code I addressed tasks in the list by their index, which is easier to input and allows me to edit a specific row rather than delete it and add a new one to the bottom.

I also checked if the input is within the list appropriately.

And I set time.sleep for the amount of seconds depending on the length of the list after printing it out.

If you want to take a look:
https://replit.com/@annabelgangster/ToDo-Advanced-45100#main.py

1 Like