python - 如何在 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]
解决方案
您可以使用itertools.product
:
from itertools import product
for route, line in product(list_of_routes, lines):
r = line.find(route)
推荐阅读
- for-loop - 如何在下面的程序中存储用户输入的值。我每次都必须输入值
- javascript - 无法访问打字稿上的属性,未定义
- spring - 有人可以帮我解决语法吗?
- python - Cython 内存分配
- python - Python & SQLite 填充数据库函数崩溃
- git - 如何删除这个 git bash 未跟踪列表
- python - 关于日期时间的“LIKE”查询的 Django ORM 语法
- r - selectInput 小部件的条件更新
- angular - Angular > 在材质表中显示列和行
- vue.js - FilePond for Vue / Nuxt:动态设置服务器属性?