- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我制作了这个程序,它需要一个吉他谱并获取音品编号并通过字典运行它,该字典获取音符并在 uke 音符字典中搜索它。
但我的问题是,如果我在 txt 文件中有一个标签,例如:
|-----11----------11----------11------11--13--11----------11----------11----------11------11--13--11---------------|
|-------13----------13----------13--------------------------13----------13----------13-----------------------------|
|--13-----13---13-----13---12-----12---------------12-13------13---13-----13---12-----12--------------------------|
|------------------------------------------------------------------------------------------------------------------|
|------------------------------------------------------------------------------------------------------------------|
|------------------------------------------------------------------------------------------------------------------|
所以我想要的是打开 txt 文件并在与该行对应的每个数字前面放一个字母。所以第一行的每个数字都会说“e”,第二行:“B”,第三行:“G”
并按顺序排列,最终结果为:G13 e11 B13 G13 等...有什么想法吗?
最佳答案
对于解析,编写一个函数,它接受一行制表符和一个音符,产生品格和位置:
import re
def parse_line(line, note):
fret_pattern = re.compile(r'\d+')
for match in fret_pattern.finditer(line):
yield (match.start(), ''.join((note, match.group(0))))
对于第一行,|-----11--
,这将产生(6, "e11")
。这些元组稍后可用于对所有字符串上的所有音符进行排序。
现在只需open()
文件,读取前 6 行并给它们正确的名称:
import itertools
notes = ['e', 'B', 'G', 'D', 'A', 'E']
with open('tab.txt') as fp:
# Read-in 6 lines
lines = itertools.islice(fp, 0, 6)
# Holds all the notes.
frets = []
# Process the lines, append all notes to frets.
for note, line in itertools.izip(notes, lines):
frets.extend(parse_line(line, note))
# Sort the frets by position.
frets.sort()
# Drop the positions.
frets = [fret for pos, fret in frets]
关于python - 吉他谱到 uke 谱程序帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7117515/
我正在尝试找到一个 C 代码程序,它可以让我计算方阵的特征值(谱)分解。我特别试图找到最高特征值(及其关联的特征值)位于第一列的代码。 我需要按此顺序输出的原因是因为我正在尝试计算特征向量中心性,因此
我正在尝试找到一个 C 代码程序,它允许我计算方阵的特征值(谱)分解。我专门尝试查找最高特征值(及其相关特征值)位于第一列的代码。 我需要按此顺序输出的原因是因为我正在尝试计算特征向量中心性,因此我只
关于从哪里开始使用 d3 制作 fiddle 图表有什么想法吗?它已经存在了吗? 我环顾四周,想出了如何使用 ggplot2 来完成此操作,并希望有一个现成的示例可供我学习,但尚未找到。 我想我可以做
我在 Glue 数据目录中定义了一个表,我可以使用 Athena 进行查询。由于表中有一些数据我想与其他 Redshift 表一起使用,我可以访问 Glue 数据目录中定义的表吗? 什么是创建外部表查
我想对一些内容进行 md5 散列,然后生成 n 个点的“曲线”或“频谱”。也就是说,要绘制从 0 到 1 的直线上的 5、10 或 20 个点,以某种方式分布,使其对于 md5 哈希是唯一的(碰撞无关
我是一名优秀的程序员,十分优秀!