python - 在python中的循环内打印
问题描述
我有两个列表,例如:
list1=["read1","read2","read3"]
list2=["read4","read5","read6"]
为了生成脚本,我需要打印它们,例如:
Programm -h -y -1 $read1,$read2,$read3 -2 $read4,$read5,$read6
我试过了:
print("Programm -h -y -1 "+str([print("$"+i,",",end='') for i in list1]))+" -2" + +str([print("$"+i,",",end='') for i in list2])))
但它确实是这样工作的,有人有想法吗?
解决方案
不确定其背后的意图,但它可能很简单:
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
推荐阅读
- c# - 部署到 iis 时,水晶报表通过 odbc postgres 驱动程序登录失败
- jquery - 砌体 - IE11 不使用 .load() 加载它
- java - Spring-Data-MongoDB:使用自定义转换器升级到 2.0.7 后无法从类型转换
- node.js - 每次检测到更改时更新绑定到 .ts 文件中函数的角度视图中的数据
- java - 在 JAVA 中初始化实例变量时
- java - Java:错误:java.lang.NullPointerException
- android - 无法使用变换 JetifyTransform 解决依赖关系?
- java - 如何更改日历对象的格式
- c# - NEST Elasticsearch C# - 问题映射嵌套索引多个行为
- java - 将 Object 类型转换为父对象时调用哪个方法