Count POS tags

Report a typo

You have a sentence in the string format in the input. Count all the POS tags. The output should be a Python dictionary with a POS tag as a key and several occurrences as a value. For example, if you have a sentence with two NN tags, then you'll get {'NN': 2} in the output.

Don't forget to tokenize the input sentence.

NLTK tagsets usually contain tuples. You can unpack a tuple with for (word, pos) in tagged

You may create a list of all POS tags in a sentence and then go through each of them. A for loop can help you.

You can count POS tags in the following way: ['NN', 'VBZ', 'ADJ', 'NN'].count('NN'). The output will be: 2. Another way to count the POS tags is to create a list of words of a specific POS and then count it with len().

Sample Input 1:

In 2002 the government of Gibraltar organised a referendum on a proposal by the UK Government to share sovereignty of the territory with Spain, and 99% of the population voted to reject it

Sample Output 1:

{'IN': 7, 'CD': 2, 'DT': 6, 'NN': 8, 'NNP': 3, 'VBD': 2, 'JJ': 1, 'TO': 2, ',': 1, 'CC': 1, 'VB': 1, 'PRP': 1}
Write a program in Python 3
# put your python code here
___

Create a free account to access the full topic