我正在处理两个单独的列表,一个split
是字符串的结果,另一个包含一个列表对象,列表对象中的第一项是字符串。
例如,
list_0: ["Hey", "hello?", "hi"]
list_1: [["Hey", 0.13, 0.14, 0, 0.58], ["hello?", 0.15, 0.16, 1, 0.23], ["hi", 0.17, 0.18, 0, 0.32]]
list_0
以正确的顺序排列,并且包含重复的值,由于它是音频文件的翻译,因此不能作为集合。在中list_1
,reference_number
每个扬声器的第三个元素是a 。
我想对翻译进行分类,找到每个单词/短语的说话者,这样我就可以看到reference_number_0
说出来的"Hey", "hi"
和reference_number_1
说的"hello?"
。
由于可能存在重复的值,因此我需要确保我没有错误地匹配第一对。
如何找到ref_number
每个完整短语的?
预期产量
0: "Hey", "hi"
1: "hello?"
作为更复杂的示例,请说我拥有aslist_0
和list_1
:
list_0: ["Have", "we", "all", "had", "lunch" yes", "yes", "not", "yet"]
list_1: [["Have", 0.0, 0.1, 0, 0.12], ["we", 0.2, 0.3, 0, 0.48], ["all", 0.4, 0.5, 0, 0.85], ["had", 0.6, 0.7, 0, 0.82], ["lunch", 0.8, 0.9, 0, 0.35], ["yes", 0.9, 1.0, 0, 0.57], ["yes", 1.1, 1.2, 1, 0.56], ["not", 1.3, 1.4, 2, 0.25], ["yet", 1.5, 1.6, 2, 0.73]]
这里有三个扬声器-0、1、2。输出应为:
0: "Have", "we", "all", "had", "lunch", "yes"
1: "yes"
2: "not", "yet"
干杯:)
只需构建列表的字典即可:
di={}
for l0,l1 in zip(list_0,list_1):
di.setdefault(l1[3],[]).append(l0)
>>> di
{0: ['Have', 'we', 'all', 'had', 'lunch', 'yes'], 1: ['yes'], 2: ['not', 'yet']}
对于您的特定输出:
>>> '\n'.join("{}: {}".format(e, ", ".join(di[e])) for e in sorted(di))
0: Have, we, all, had, lunch, yes
1: yes
2: not, yet
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句