我以这种元组格式从文件中读取标题数据("string " , start_time , end_time)
,并希望将两行合并为一个元组。你知道吗
with open(fname) as f:
content = f.readlines()
# remove whitespace character
content = [x.strip() for x in content]
for index, line in enumerate(content):
if line.startswith('<p class=KRCC>'):
trans = line.strip('<p class=KRCC>')
start_time = int(re.search(r'\d+', content[index -1]).group())
end_time = int(re.search(r'\d+', content[index +1]).group())
myTuple = (trans, start_time, end_time)
print myTuple
("I said that you had a nice butt. It's just not a great butt.", 1658412, 1662644)
("You wouldn't know a great butt if it bit you.", 1663012, 1665606)
("There's an image.", 1665852, 1667331)
('Would anybody like more coffee?', 1669612, 1671523)
('Did you make it?', 1673372, 1675044)
我想把两句话连成一个元组。例如,我想把两个句子组合起来,比如(1, 2)
、(2, 3)
、(3, 4)
和(4, 5)
,去掉中心时间值。你知道吗
例如
(1, 2)
("I said that you had a nice butt. It's just not a great butt.You wouldn't know a great butt if it bit you.", 1658412, 1665606)
(2, 3)
("You wouldn't know a great butt if it bit you.There's an image", 1663012, 1667331)
(3, 4)
("There's an image.Would anybody like more coffee?", 1665852, 1671523)
(4, 5)
('Would anybody like more coffee?Did you make it?', 1669612, 1675044)
你们能给我一些建议或帮助吗?这对我真的很有帮助。你知道吗
如果列表中有元组:
像这样的?你知道吗
示例:
相关问题 更多 >
编程相关推荐