Exercises
○ Try using the Python interpreter as a calculator, and typing expressions like
12 / (4 + 1).○ Given an alphabet of 26 letters, there are 26 to the power 10, or
26 ** 10, 10-letter strings we can form. That works out to141167095653376L(theLat the end just indicates that this is Python’s long-number format). How many hundred-letter strings are possible?○ The Python multiplication operation can be applied to lists. What happens when you type
['Monty', 'Python'] * 20, or3 * sent1?○ Review Computing with Language: Texts and Words on computing with language. How many words are there in
text2? How many distinct words are there?○ Compare the lexical diversity scores for humor and romance fiction in Table 1-1. Which genre is more lexically diverse?
○ Produce a dispersion plot of the four main protagonists in Sense and Sensibility: Elinor, Marianne, Edward, and Willoughby. What can you observe about the different roles played by the males and females in this novel? Can you identify the couples?
○ Find the collocations in
text5.○ Consider the following Python expression:
len(set(text4)). State the purpose of this expression. Describe the two steps involved in performing this computation.○ Review A Closer Look at Python: Texts as Lists of Words on lists and strings.
Define a string and assign it to a variable, e.g.,
my_string = 'My String'(but put something more interesting in the string). Print the contents of this variable in two ways, first by simply typing the variable name ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access