简体   繁体   中英

extract words from string python and add them in array using nlp

I have this problem in Python. I will import a line like say "Mary has a little lamp." I need to implement NLP so that I can put each word into an array. So the output will be a[0] = 'Mary' and so on.


import nltk
from nltk.corpus import wordnet 
from nltk.tokenize import word_tokenize
i = 0 
mytext = "Hello Mr. Adam, how are you? I hope everything is going well. Today is a good day, see you dude."
blah = [word_tokenize(i) for i in mytext]
blah[1]

The output gives 'e'

Just use:

blah = word_tokenize(mytext)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM