我是python和编码的新手(昨晚)。我需要生成大量具有特定输出格式的itertools产品。我可以使用
生成组合import itertools
s=[ ['CPT1','OTHERCPT1','OTHERCPT2','OTHERCPT3','OTHERCPT4','OTHERCPT5','OTHERCPT6','OTHERCPT7','OTHERCPT8','OTHERCPT9','OTHERCPT10','CONCURR1','CONCURR2','CONCURR3','CONCURR4','CONCURR5','CONCURR6','CONCURR7','CONCURR8','CONCURR9','CONCURR10'], ['15756','15757','15758','43496','49006','20969','20955','20956','20957','20962','20970','20972','20973'],['CPT1','OTHERCPT1','OTHERCPT2','OTHERCPT3','OTHERCPT4','OTHERCPT5','OTHERCPT6','OTHERCPT7','OTHERCPT8','OTHERCPT9','OTHERCPT10','CONCURR1','CONCURR2','CONCURR3','CONCURR4','CONCURR5','CONCURR6','CONCURR7','CONCURR8','CONCURR9','CONCURR10'], ['15756','15757','15758','43496','49006','20969','20955','20956','20957','20962','20970','20972','20973']]
x=list(itertools.product(*s))
print x
然而输出显示如下:
('CPT1', '15756', 'CPT1', '15756'), ... etc.
我希望它出现:
SELECT IF(CPT1='15756' AND CPT1='15756').
SELECT IF(...).
etc.
感谢您的帮助!
答案 0 :(得分:1)
您应该使用字符串格式(https://docs.python.org/2/library/string.html)
import itertools
s = [[...first list...],[...second list...]]
for p in itertools.product(*s):
print("SELECT IF(CPT1='{}' AND CPT1='{}').".format(*p))