【发布时间】:2019-01-27 11:34:45
【问题描述】:
例如:
result=[]
todolist=mongo.db.Todo.find()
for todo in todolist:
for detail in todo['list']:
result.append(str(detail))
我正在寻找避免嵌套 for 循环的最佳方法。 我是新手。 谁能帮我?谢谢。
【问题讨论】:
-
你的嵌套循环有什么问题?
-
你有类似
result = [str(detail) for todo in todolist for detail in todo['list']]的列表理解吗? -
好的,我删除了我的答案,因为你说你不想使用
for循环。 -
我的意思是我想避免嵌套 for 循环。