+ 1

How to print the words alone without the pos tag in nltk?!

>>> import nltk >>> o='hello this is my project report' >>> tokens = nltk.word_tokenize(o) >>> print(tokens) ['hello', 'this', 'is', 'my', 'project', 'report'] >>> p=nltk.pos_tag(words) >>> print(p) [('hello', 'NN'), ('this', 'DT'), ('is', 'VBZ'), ('my', 'PRP

#x27;), ('project', 'JJ'), ('report', 'NN')] >>> obj = list(filter(lambda x:x[1]=='NN',p)) >>> print(obj) [('hello', 'NN'), ('report', 'NN')] i need output like [('hello'),('report')]

11th Dec 2020, 4:11 PM
Lakshmi Aravindarajan
Lakshmi Aravindarajan - avatar
2 Antworten
11th Dec 2020, 5:11 PM
Mohammed Qadir Khan
Mohammed Qadir Khan - avatar
+ 1
Not sure if you can get the exact output, as python won't recognise the ('hello') as a tuple without an extra comma in it. i.e ('hello',) unless the nltk (what ever that is) can do it. print([x for x, y in obj])
11th Dec 2020, 4:43 PM
rodwynnejones
rodwynnejones - avatar