0
1
00:00:00,210 --> 00:00:00,930
Hey,
1
2
00:00:00,930 --> 00:00:05,280
welcome to day 50 of your course
2
3
查看您提供的输入,我假设所讨论的文件是一个srt文件。在这种情况下,你很有可能在0 1
部分犯了错误。如果是这种情况,您可以简单地使用isnumeric()
方法来删除完全是数字的字符串。一个相同的例子是:
f = open("infile.srt", "r")
data = f.read().splitlines()
cleaned_data = []
for eachLine in data:
if not(eachLine.isnumeric()) and len(lineText)>1:
cleaned_data.append(eachLine)
print(cleaned_data)
但是如果0 1
是一个常见的外观,你可以使用一个额外的检查条件,没有空格,这可以用代码来完成:
f = open("infile.srt", "r")
data = f.read().splitlines()
cleaned_data = []
for eachLine in data:
lineText = eachLine.replace(" ", "")
if not(lineText.isnumeric()) and len(lineText)>1:
cleaned_data.append(eachLine)
print(cleaned_data)