Teaching Python

We're two middle school teachers learning and teaching Python

The NLTK library and Real Python Projects from Lee Vaughan

I have been 'gifted' more books by my wonderful colleague. This project is from Lee Vaughan's "Real World Python" Chapter 3. I recommend this book for all Python learners!

The best thing about Python is that there are many Python libraries and projects that facilitate teaching complex topics in other curricula. From data science and graphs to probability and math to analyzing text, Python makes learning complicated concepts unique!

Analyzing extensive or lengthy text is one skill that is common in both English and Humanities courses. Students often have difficulty finding meaning or comprehending text. However, two python libraries useful for "scraping" the web and understanding language are Beautiful Soup and the NLTK project.

The NLTK project library is "a wonderful tool for teaching, and working in, computational linguistics using Python," it is "an amazing library to play with natural language." Overall, the NLTK library helps the computer to analyze written text.

Literacy experts have determined that readability for multiple ages increases when a sentence is 15 words or less. This code allows the user to select sentence length and the number of sentences to extract from the text to produce text that is easier to read and comprehend the text's overall meaning.

This project from the book Real Python Projects is an excellent example of how these two libraries work together and can help English teachers, teaching reading comprehension skills and analyzing text.

In this well explained and elegant project, each function is defined and explained.

The program gets a text from a website (requests library), tokenizes it into smaller sentences, removes stopwords or words with little meaning, and then looks for words with a higher frequency.

In Vaughan's example, he uses Martin Luther King's "I have a dream" speech. This speech is also useful in school and is a great activity to use in January to highlight Dr. Martin Luther King's birthday. It is also an excellent example to demonstrate how the NLTK library works. (To read more about the NLTK library, check out this tutorial from Data Camp, "Text Analytics for Beginners."

Projects like these are great ways to incoorporate authentic assessments and projects into any classroom.