我有一个字典和一个嵌套的for循环,如下所示:
dictionary = {container: {row: [(tuple), (tuple)]}}
for box in box_df.index:
for container in container_df.index:
for row in dictionary[container].keys():
if condition:
dictionary[container][row + 1] = [(tuple)]我需要的是,如果添加了新的行,我想在按顺序移动到框之前尝试它。如果我在conditional之后使用continue,它会返回一个运行时错误,因为迭代器已经改变了大小。如果我使用break,它会移到下一个框。
我有点卡住了。
发布于 2020-12-20 09:57:33
为了避免在循环过程中更改迭代器,使用它来列出列表,然后遍历列表
for row in list(dictionary[container].keys()):https://stackoverflow.com/questions/65376187
复制相似问题