Week 11: Lists and arrays
Python code typing course. 20 wpm, 93% accuracy.
A list holds several values in one place. In Python, a list is written between square brackets, and its items are separated by commas. You can read an item by its position number. Positions start at 0, so the first item is at position 0 and the second at position 1. This week you practice writing lists, placing commas correctly, and matching every pair of brackets.
What you will learn
On the US English layout, the three symbols are typed like this:
[is the[key, pressed with the right pinky.]is the]key, pressed with the right pinky.,is the comma key, pressed with the right middle finger.
Here is a list and a line that reads its first item:
fruits = ["apple", "pear"]
print(fruits[0])
The first line creates a list of two text items, separated by a comma. The second line prints the item at position 0, which is apple. Because counting starts at 0, the first item always sits at 0.
Technique tips
- Type the opening square bracket, then immediately the closing one. Fill in the items afterwards.
- Keep your right pinky steady for the
[and]keys, since both use it. - Put a space after each comma. The space helps you see where each item starts and ends.
- When you read an item by position, check that the number inside the brackets is the one you intended. Remember that counting starts at 0.
- Text items need quotation marks. Keep the quotation marks and commas in mind as you type each item.
Lessons
- Lesson 1 (10 to 15 minutes): Learn. Watch the keyboard demo for the square brackets and the comma. Then type
fruits = ["apple", "pear"]slowly. - Lesson 2 (10 to 15 minutes): Practice. Repeat
print(fruits[0])and similar lines. Check that the brackets and commas match in every list. - Lesson 3 (10 to 15 minutes): Review. Take the 2-minute test built from this week’s lists. Note the lines where a bracket or comma went missing and repeat them next session.
This week’s goal
The goal is 20 wpm with 93% accuracy. The first star comes when you finish the lessons. The second star comes at 93% accuracy, and the third when you also reach 20 wpm. A missing bracket or comma stops the list from working, so get the pairs right first.
Symbols this week
The colored keys are the ones you learn this week. The color shows which finger presses the key.
This week’s lessons
Do the lessons in order. Each one ends with a test, and your best result is saved.