I’m new to Python and have some questions about lists and tuples.
I’ve got a list consisting of tuples with sentences and wordclass-tags. This is one element in my list:
[('It', 'PPS'), ('says', 'VBZ'), ('that', 'CS'), ('``', '``'), ('in', 'IN'), ('the', 'AT'), ('event', 'NN'), ('Congress', 'NP'), ('does', 'DOZ'), ('provide', 'VB'), ('this', 'DT'), ('increase', 'NN'), ('in', 'IN'), ('federal', 'JJ'), ('funds', 'NNS'), ("''", "''"), (',', ','), ('the', 'AT'), ('State', 'NN-TL'), ('Board', 'NN-TL'), ('of', 'IN-TL'), ('Education', 'NN-TL'), ('should', 'MD'), ('be', 'BE'), ('directed', 'VBN'), ('to', 'TO'), ('``', '``'), ('give', 'VB'), ('priority', 'NN'), ("''", "''"), ('to', 'IN'), ('teacher', 'NN'), ('pay', 'NN'), ('raises', 'NNS'), ('.', '.')]
As you can see each word has a wordclass-tag. How can I search after word + wordclass in my list? F.ex. if I would like to see if the element about contains the word “federal” attached to the wordclass-tag “JJ” ?
Help is much appreciated
To check if you have the word ‘federal’ tagged with ‘JJ’ on your list:
Using list comprehension syntax you can do more interesting things with your list, for example see all tags of all occurrences of a word:
It’s good to build some functions doing generic operations on the data structure you work with, like checking if it contains a word or tag:
To answer your question in the comments: