I am trying to compare a list of forbidden folders read from a file. But we have to check if the task has the parent ID of the folder and then if that folder matches the forbidden folder. The lists I am looping through can contain many items.
for task in tasks:
#Check the task is on their timesheet
if task["id"] == entry["item_id"]:
for folder in folders:
#See if the task is inside the folder
if task["parent_id"] == folder["id"]:
for forbiddenFolder in forbiddenFolders:
#If the folder is on the list
if forbiddenFolder == folder["name"]:
body_of_email +=( "Using a task within a folder that is not permiited " + forbiddenFolder + "\r\n" )
folder["name"]
break
This code uses three nested for
loops, which might be slow. Can I make this more efficient?