1
我需要修复此程序,以便从解压缩的文件中删除标点符号。例如,当文件原始文本被解压缩时,单词和标点符号之间有空格。在python中压缩和解压缩文本文件
例如:cheese ,
应该返回cheese,
def RemoveSpace(ln): #subroutine used to remove the spaces after the punctuation
line = ""
line2 = ""
puncpst = []
for g in range(1, len(line)):
if line[g] == "." or line[g] == "," or line[g] == "!" or line[g] == "?":
puncpst.append(g) #get the positions of punctuation marks in a list
for b in range(len(line)):
if b + 1 not in puncpst:
line2 = line2 + line[b]
return line2
EF RemoveSpace(LN):所使用的标点符号 行之后以删除空格#subroutine = “” LINE2 =” “ puncpst = [] g范围内(1,len(行)): if line [g] ==”。“或行[g] ==“,”或行[g] ==“!”或线[g] ==“?”: puncpst.append(g)#如果b + 1不在puncpst中,请为列中的b获取标点符号列表 中的位置: : line2 = line2 + line [b] return line2 – Manal
您应该确保您的程序格式正确。 Python对此非常关注。除此之外,我没有看到你的程序如何检查标点符号之前是否有空格。 – quamrana