CS110A Week 11 Day 1 lesson on Tuesday 10/27/2026
Overview
Indika Walimuni uses a handwritten-address example to teach Python string splitting, indexing, and function design, then develops the lesson into list sequences, mutability, and list methods. Students finish with a Google Colab and Matplotlib exercise using U.S. Census Bureau California population data, where they add a density-rank plot and label the charts.
Key takeaways
- Python's split() method returns a list, and negative indexing makes it straightforward to select the final address token before parsing a ZIP+4 value with a dash delimiter.
- A clear algorithm can be written before implementation: split the address, select its first and last tokens, split the ZIP token, and return the required values as a tuple.
- Python strings are immutable, so changing a character by index fails; lists are mutable, so item assignment updates the existing list object.
- List methods such as append() and pop() modify lists in place, while index() returns a matching position or raises ValueError when the value is absent.
- The California population assignment applies list and plotting concepts in Google Colab, adding a blue-star density-rank-versus-year plot and meaningful chart and axis labels.
Chapters
- Indika Walimuni describes how postal sorting can use barcode readers or cameras to capture handwritten addresses.
- Optical character recognition converts an address image into text, using machine-learning models trained on many handwriting examples.
- Once text is available, software can extract a ZIP code and route mail to the corresponding sorting bin.
- The sample problem takes a multiline street address as a Python string.
- The desired result is a tuple containing the house number and ZIP code.
- Indika identifies the function vocabulary as an address input and a returned tuple, establishing the types before coding.
- Python's string documentation identifies split() as the method for turning a phrase into a list of words.
- Calling address.split() uses whitespace as the default delimiter and stores the resulting tokens in a list.
- The first list element, accessed with index 0, holds the house number in the sample address.
- The final address token is accessed with parts[-1], applying negative indexing to a list.
- A ZIP+4 token is split again using '-' as the delimiter, producing the five-digit ZIP and its extension.
- Index 0 of the second split result selects the five-digit ZIP code.
- The plan starts by accepting the address and splitting it into words using whitespace.
- It then selects the final token, splits that complex ZIP code on a dash, and prepares the requested output.
- Indika emphasizes descriptive steps because explicit plans are easier to translate into code with fewer errors.
- The function takes address as its parameter and documents that it returns a house-number and ZIP-code tuple.
- Its code follows the English plan: split the address, access the first and last tokens, then split the ZIP token.
- The function is tested with an address from Houston, Texas, including ZIP code 77023.
- A ZIP token without a dash remains a one-item split result, so selecting its first element still works in that example.
- The function returns a tuple, whose first and second values can be accessed using indices 0 and 1.
- Negative index -1 selects the rightmost element of sequences such as strings, lists, and tuples.
- The address split omits its delimiter to use Python's default whitespace behavior, while ZIP parsing explicitly supplies '-'.
- Python uses + to concatenate strings, combining text in a way comparable to joining parts of a paragraph.
- Adding an integer directly to a string raises a TypeError because the operands have incompatible types.
- Converting the integer to a string allows it to be concatenated with other string values.
- The lesson introduces strings, tuples, and lists as Python sequence types.
- Strings contain characters, while lists can contain objects of different types, making lists heterogeneous.
- Sequence ordering supports indexing, with 0 for the first element and -1 for the last.
- Indika discusses the idea of grading performance as 'not yet' rather than treating a current difficulty as permanent failure.
- He recommends an educational video describing research on learning and the 'power of yet.'
- The lesson then returns to Python lists and their shared indexing behavior with other sequences.
- A list can be written with square brackets and comma-separated values, including strings, floats, and integers.
- The empty list [] initializes a list with no elements.
- A Python Tutor visualization shows a prices list in the global frame and illustrates its indexed items.
- An f-string begins with f before its quoted text and uses curly braces to embed expressions.
- A list value can be displayed by placing its name and an index, such as prices[index], inside braces.
- The formatting combines explanatory text with values from the list in a readable printed result.
- Attempting to assign a new character to py[0] raises a TypeError because strings do not support item assignment.
- Assigning the name py to the string 'Jython' is allowed, but it rebinds the variable rather than changing the original string.
- Indika compares object IDs to show that the reassigned string is a separate object from the original.
- Calling list('Python') constructs a list containing the individual characters of the string.
- Assigning 'J' to pi_list[0] changes the first element while retaining the same list object.
- The contrast with string item assignment demonstrates that Python lists are mutable and strings are immutable.
- Indika explains that multiple names can refer to a mutable list, so changes through one reference can affect the shared object.
- He introduces this risk as aliasing and previews a later class discussion about it.
- He describes string immutability as useful for safe sharing and optimization, while mutable lists offer more flexibility.
- Calling dir(list) or dir([]) reveals available list methods, including append, insert, pop, and remove.
- append('P') adds an element to the end of a list such as [1, 2, 3].
- pop() removes the final element by default, while pop(0) removes the element at index 0.
- These methods modify the existing list rather than creating a replacement list.
- The built-in len() function counts elements in sequences such as strings, lists, and tuples.
- Python also provides sequence operations including concatenation, min(), and max(); sum() is useful for lists of numbers.
- The list method index(2) returns 1 for [1, 2, 3], while searching for a missing value such as 'P' raises a ValueError.
- Indika assigns a data-oriented exercise in course module 8 after introducing the list knowledge needed to work with the data.
- A Google Colab notebook imports historical California population data associated with the U.S. Census Bureau.
- The provided code already generates plots from lists, so students focus on understanding and adapting the template.
- The notebook currently plots California total population and population density against year using Matplotlib subplots.
- Students must add a third plot showing density rank versus year, using blue star markers.
- The assignment also asks for a meaningful chart title and labels for the x- and y-axes.
- The provided plotting functions arrange charts as either one row with multiple columns or one column with multiple rows.
- Adding the density-rank chart requires updating the subplot configuration, for example increasing the column count for a horizontal layout.
- Indika asks students to read the comments, follow the existing plot patterns, run the notebook, and try the changes before doing them together.
Transcript excerpt
0:00 Good morning, guys. This is our agenda today. So, So, let's go to um So, we're going to solve that problem that uh the address problem, right? Um this one. So, this is actually what the um something like this um I mean, this is really a simple simplified scenario, right? Um but uh United States Postal Office does something like use something like this. So, what they do is So, um they collect mails and then some of them have barcodes, right? I mean, it's
0:47 especially if you mail the um mail inside the post office, you get a barcode. And you know that it's easy to read a barcode. It has everything, right? So, nowadays we have technology. But, you know, people still write the address by hand, right? So, they handwrite like for example, say a greeting card, handwrite and put the stamp and then mail. So, all those mails, they collect and then they put in a sorting machine, right? And then the all those mail including boxes goes in a conveyor belt and then then uh they basically turned and then there's a camera taking pictures and then also alongside barcode readers. So, if there's no barcode, then then the camera take a picture and then then basically um you know, tokenize that picture into
1:36 text. Okay? So, we call that uh algorithm optical character recognition. Optical means there's a camera and then take a picture. So, you have now a picture of the address. It's an image. It's not text, right? And then you tokenize using machine learning algorithm called optical character recognition. Basically, when you run that uh an address um, like, you know, of an address through that and it's basically convert the image into text, right? So, that's optical character recognition. It's a well-known and
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, indika walimuni.