首页 > 解决方案 > 如何在 1 行中为迭代器更改 2

问题描述

我有这两个迭代器:

for i in range(len(list_of_routes)):#
    for b in range(len(lines)):         
        r = lines[b].find(list_of_routes[i])

如何简化?

附言

例如:

list_of_routes = [route1, route2, route3]
lines = [info for route1, info for route2, info for route3, info for route2]

标签: pythonloops

解决方案


您可以使用itertools.product

from itertools import product

for route, line in product(list_of_routes, lines):
    r = line.find(route)

推荐阅读