Best way to strip punctuation from a string

前端 未结 26 1881
日久生厌
日久生厌 2020-11-21 05:39

It seems like there should be a simpler way than:

import string
s = \"string. With. Punctuation?\" # Sample string 
out = s.translate(string.maketrans(\"\",\         


        
26条回答
  •  一生所求
    2020-11-21 05:50

    with open('one.txt','r')as myFile:
    
        str1=myFile.read()
    
        print(str1)
    
    
        punctuation = ['(', ')', '?', ':', ';', ',', '.', '!', '/', '"', "'"] 
    
    for i in punctuation:
    
            str1 = str1.replace(i," ") 
            myList=[]
            myList.extend(str1.split(" "))
    print (str1) 
    for i in myList:
    
        print(i,end='\n')
        print ("____________")
    

提交回复
热议问题