Homework 3: the Terminal & Beginning Python
LIN 301: Computation for Linguists
Part 1: Terminal (Setup)
- Open your Terminal in RStudio.
- Navigate (
cd) into your course repo folder (LIN_301).
- Make a new folder called
hw3_files. - Download the file shakespeare.txt from Project Gutenberg into that folder (use
curl). The file is located at this address: https://www.gutenberg.org/cache/epub/100/pg100.txt.
- Confirm the file is in your folder with the
lscommand.
Part 2: Python (Lists and Dictionaries)
Create a new Quarto doc called hw3.qmd with a Python code chunk.
Load the File
In the first part of your Quarto doc, run the following code. This assigns the text found in shakespeare.txt to a variable named text.
with open("hw3_files/shakespeare.txt", "r", encoding="utf-8") as f:
text = f.read()Make a List
- Using the method
.split()[:1000], take the first 1000 words (in the order they appear) and store them in a list calledfirst_words.
- Print the list.
- Print the 500th item in the list.
Narrowing down the List
- Now pick 10 of the words from your
first_wordslist. You should pick super common ones (like ‘the’) and rarer ones, too. - Manually place these 10 words in a new list called
chosen_ones.
Make a Dictionary
- You’re now going to create a third list, called
bill, that will contain all of the words of Shakespeare. As before, use the method.split()to splitshakespeare.txtinto separate words. - Use the method
.count()to see how many times each chosen appears in the text.
- Create a dictionary called
word_countsthat pairs each chosen word with its number. - Do not manually insert the counts in your
dict. You should use the format:"word": text.count("word").
Part 3: Reflection
At the bottom of your hw3.qmd, write a short (3–5 sentence) reflection:
- What was easiest about this assignment?
- What was hardest?
- How might a linguist use lists and dictionaries for language data?
Submission
- Upload hw3.qmd file to Canvas.