我正在尝试比较从文件中读取的禁止文件夹列表。但是我们必须检查任务是否具有文件夹的父 ID,然后检查该文件夹是否与禁止文件夹匹配。我正在循环的列表可以包含许多项目。
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
此代码使用三个嵌套for
循环,这可能会很慢。我可以提高效率吗?