我有两个列表,例如:
img*=(4095/65535.);
并且为了生成脚本,我需要打印它们,例如:
list1=["read1","read2","read3"]
list2=["read4","read5","read6"]
我尝试过:
Programm -h -y -1 $read1,$read2,$read3 -2 $read4,$read5,$read6
但是它确实可以工作,有人有想法吗?
答案 0 :(得分:2)
不确定要隐含的意图,但是它可能很简单:
List1 = ['read1', 'read2', 'read3']
List2 = ['read4', 'read5', 'read6']
List1 = ["$"+(i) for i in List1]
List2 = ["$"+(i) for i in List2]
print('Programm -h -y -1', end=" ")
print(",".join(List1) + " -2 " + ",".join(List2))
编辑:
甚至更好,谢谢@Matt B。
List1 = ['read1', 'read2', 'read3']
List2 = ['read4', 'read5', 'read6']
print("Programm -h -y -1 " + "$" + ",$".join(List1) + " -2 $" + ",$".join(List2))
输出:
Programm -h -y -1 $read1,$read2,$read3 -2 $read4,$read5,$read6
答案 1 :(得分:2)
使用$
在列表中添加list-comprehension
,然后使用join
从list
创建一个字符串。
List1=['read1','read2','read3']
List2=['read4','read5','read6']
List1 = ["$"+str(i) for i in List1]
List2 = ["$"+str(i) for i in List2]
x = "Programm -h -y -1 {} -2 {}".format(",".join(List1), ",".join(List2))
print(x)
输出:
Programm -h -y -1 $read1,$read2,$read3 -2 $read4,$read5,$read6