Best way to strip punctuation from a string

前端 未结 26 1891
日久生厌
日久生厌 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条回答
  •  梦毁少年i
    2020-11-21 05:57

    Remove stop words from the text file using Python

    print('====THIS IS HOW TO REMOVE STOP WORS====')
    
    with open('one.txt','r')as myFile:
    
        str1=myFile.read()
    
        stop_words ="not", "is", "it", "By","between","This","By","A","when","And","up","Then","was","by","It","If","can","an","he","This","or","And","a","i","it","am","at","on","in","of","to","is","so","too","my","the","and","but","are","very","here","even","from","them","then","than","this","that","though","be","But","these"
    
        myList=[]
    
        myList.extend(str1.split(" "))
    
        for i in myList:
    
            if i not in stop_words:
    
                print ("____________")
    
                print(i,end='\n')
    

提交回复
热议问题