re.sub erroring with “Expected string or bytes-like object”

前端 未结 3 1583
青春惊慌失措
青春惊慌失措 2020-11-29 05:10

I have read multiple posts regarding this error, but I still can\'t figure it out. When I try to loop through my function:

def fix_Plan(location):
    letter         


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-29 05:20

    I suppose better would be to use re.match() function. here is an example which may help you.

    import re
    import nltk
    from nltk.tokenize import word_tokenize
    nltk.download('punkt')
    sentences = word_tokenize("I love to learn NLP \n 'a :(")
    #for i in range(len(sentences)):
    sentences = [word.lower() for word in sentences if re.match('^[a-zA-Z]+', word)]  
    sentences
    

提交回复
热议问题