浏览量 4578
2017/05/03 19:14
通过 from itertools import product 避免多重循环,提高可读性
#!/usr/bin/env python
# coding=utf-8
# author: wz
# mail: 277215243@qq.com
# datetime:2017/5/3 6:32 PM
# web: https://www.bthlt.com
from itertools import product
a_list=["a1","a2","a3"]
b_list=["b1","b2","b3"]
c_list=["c1","c2","c3"]
for a in a_list:
for b in b_list:
for c in c_list:
if "2" in a and "2" in b and "2" in c:
print a,b,c
#用product实现,避免多重循环
for a,b,c in product(a_list,b_list,c_list):
if "2" in a and "2" in b and "2" in c:
print a, b, c
上一篇 搜索 下一篇