This is computational linguistics, and the book accompanying the open- source Natural Language Toolkit, Natural Language Processing with Python --- Analyzing Text with the Natural Language Toolkit, is available as a paper book and free online.
Chapter five covers "part-of-speech tagging" or POS-tagging with the NLTK in detail, using Python dictionaries:
As we have seen, a tagged word of the form (word, tag) is an association between a word and a part-of-speech tag. Once we start doing part-of-speech tagging, we will be creating programs that assign a tag to a word, the tag which is most likely in a given context. We can think of this process as mapping from words to tags. The most natural way to store mappings in Python uses the so-called dictionary data type (also known as an associative array or hash array in other programming languages). In this section we look at dictionaries and see how they can represent a variety of language information, including parts of speech.
It also covers several methods of automatically tagging text to identify POS in text with unknown words.
Some other introductory books to computational linguistics have ben suggested at Linguistics.SELinguistics.SE, where you can ask further questions on the topic.