python - 打印时如何排除逗号、方括号和大括号?(Python)
问题描述
我希望下面代码的打印语句排除逗号、方括号和大括号。像这样:
三音符三阶进阶:D♯ C F♭ᵒ C♯</p>
起始位置:632根位置
# Three-Note Triad Generator
import random
roots = ("A", "A♯", "B", "B♯", "C", "C♯", "D", "D♯", "E", "E♯", "F", "F♯", "G", "G♯", "A♭", "B♭", "C♭", "D♭", "E♭", "F♭", "G♭")
triad_types = ('', '⁻', '⁺', 'ᵒ')
three_string_groups = ('654', '653', '652', '651', '643', '642', '641', '632', '631', '621', '543', '542', '541', '532','531', '521', '432', '431', '421', '321')
inversion = ("Root Position", "1st Inversion", "Second Inversion")
print("\n\n\nTHREE-NOTE TRIADS PROGRESSION:")
print((random.sample(roots, 1)) + (random.sample(triad_types, 1)))
print((random.sample(roots, 1)) + (random.sample(triad_types, 1)))
print((random.sample(roots, 1)) + (random.sample(triad_types, 1)))
print((random.sample(roots, 1)) + (random.sample(triad_types, 1)))
print("\nStarting Position:")
print((random.sample(three_string_groups, 1)) + (random.sample(inversion, 1)))
解决方案
您可以使用 unpacking with*
从列表中获取字符串。
例如:
print(*(random.sample(roots, 1) + random.sample(triad_types, 1)))
哪个打印:
B♭
推荐阅读
- r - 如何通过使用plot()函数R通过分类列的值增加颜色的阴影来为绘图着色
- javascript - 如何在发送到服务器之前将 mimetype (video/webm) 和编解码器 (vp9) 添加到 blob 对象
- php - 如何使用 laravel 注册验证器返回错误
- php - 在php中搜索带有条件的数组
- angular - 为什么 Chrome 在使用 Angular Service-Worker 时会显示重复的 HTTP 请求?
- elasticsearch - Elasticsearch - cologne 和 koelnerphonetik 编码器的区别
- java - 在 API Retrofit PUT 调用中将自定义对象数组作为参数传递
- angular - ngmodule 不是子类型 ngmoduletype
- linux - Git不使用user.name
- python - Gunicorn 工作人员在长时间 API 调用后自行重启