Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 匹配音节和音符_Python - Fatal编程技术网

Python 匹配音节和音符

Python 匹配音节和音符,python,Python,示例:假设我有4个注释 [A,B,C,D] 我有6个音节 [hi, my, name, is bob, by] 我如何使这4个音符一次又一次地循环,直到它为音节指定了一个音符?所以 hi=a, my=b, name=c, is=d, bob=a, by= a ? 我有这样的想法: for i in range(0, index): print(Notes[i], Syllables[i]) 使用itertools。例如: # two lists of strings notes =

示例:假设我有4个注释

[A,B,C,D]
我有6个音节

[hi, my, name, is bob, by]
我如何使这4个音符一次又一次地循环,直到它为音节指定了一个音符?所以

hi=a, my=b, name=c, is=d, bob=a, by= a
?

我有这样的想法:

for i in range(0, index):
  print(Notes[i], Syllables[i])

使用
itertools
。例如:

# two lists of strings
notes = ['A','B','C','D']
syllables = ['hi', 'my', 'name', 'is', 'bob', 'by']

# import cycle from itertools
from itertools import cycle
# create an iterator
cycled = cycle(notes) 

# loop through and output what you requested
for i in range(len(syllables)):
    print(syllables[i], next(cycled))
这将产生:

'hi' 'A'
'my' 'B'
'name' 'C'
'is' 'D'
'bob' 'A'
'by' 'B'

is
bob
之间是否应该有逗号?那么,这个问题似乎是不完整的
by=a
使它更加混乱。是不是应该有
by=b
?我也会回答同样的问题,但根据OP的例子,
by
应该与
A
搭配,这是一个很好的观点。我认为这是一个错误,因为还有一些像你指出的错误。如果OP澄清了“注释”是如何分配的,我将更改我的答案。