How to print the words alone without the pos tag in nltk?! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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 Panneerselvam
Lakshmi Panneerselvam - avatar
2 Answers
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