多重嵌套循环在Python问题,怎么解决

如题所述

使用自定义异常可以跳出深层嵌套循环、看我做过的例子:
class FoundException(Exception): pass
try:
for row,record in enumerate(table):
for columu,field in enumerate(record):
for index,item in enumerate(field):
if item == target:
raise FoundException()
except FoundException:
print ("found at ({0},{1},{2})".format(row,column,index))
else:
print ('not found')
温馨提示:答案为网友推荐,仅供参考