For example, search Once you've spent a little while examining these texts, we hope you have a new sense of the richness and diversity of language. Each stripe represents an instance of a word, and each row represents the entire text.In the next chapter you will learn how to access a broader range of text, including text in languages other than English. In 1.2 we see some striking patterns of word usage over the last 220 years (in an artificial text constructed by joining the texts of the Inaugural Address Corpus end-to-end). You might like to try more words (e.g., The most obvious fact about texts that emerges from the preceding examples is that they differ in the vocabulary they use.
Instead, you can come up with your own name for a task, like "lexical_diversity" or "percentage", and associate it with a block of code.Now you only have to type a short name instead of one or more complete lines of Python code, and you can re-use it as often as you like.Test your understanding by modifying the examples, and trying the exercises at the end of the chapter.Let's begin by finding out the length of a text from start to finish, in terms of the words and punctuation symbols that appear. But there are only four distinct vocabulary items in this phrase.After printing a welcome message, it loads the text of several books (this will take a few seconds).
Here's the command again, together with the output that you will see.
Take care to get spelling and punctuation right, and remember that you don't type the Note Your Turn: Try searching for other words; to save re-typing, you might be able to use up-arrow, Ctrl-up-arrow or Alt-p to access the previous command and modify the word being searched.
You can also try searches on some of the other texts we have included.
In this section we will see how to use the computer to count the words in a text in a variety of useful ways.
As before, you will jump right in and experiment with the Python interpreter, even though you may not have studied Python systematically yet.
Once the data is downloaded to your machine, you can load some of it using the Python interpreter.