✸ ✸ ✸
通过 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
✸ ✸ ✸
📜 版权声明
本文作者:王梓 | 原文链接:https://www.bthlt.com/note/11190366-Pythonproduct避免多重循环
出处:葫芦的运维日志 | 转载请注明出处并保留原文链接


📜 留言板
留言提交后需管理员审核通过才会显示