CS110A Week 12 Day 1 lesson on Tuesday 11/03/2026
Overview
Indika Walimuni teaches CS110A students to solve an anagram problem with Python’s built-in `sorted` function, then introduces branching with `if`, `elif`, and `else`, Boolean expressions, comparison operators, and chained comparisons. The lesson also explains truthiness and short-circuit evaluation through the guardian pattern, and assigns a grade-calculation exercise using a dictionary while prohibiting `for` loops.
Key takeaways
- For anagram testing, `sorted(word_one) == sorted(word_two)` compares the character contents independent of order and returns a Boolean without writing a loop.
- Sorting an entire string with Python’s built-in `sorted` produces a list of characters, so list equality can determine whether two words contain the same letters.
- Short-circuit evaluation makes `Y != 0 and X / Y > threshold` a safe guard: when `Y` is zero, Python stops before division.
- Python treats `None`, `False`, zero, and empty containers as falsy, while a nonempty list can be used directly as an `if` condition.
- Chained comparisons express bounded ranges compactly: `9 <= user_grade <= 12` includes both endpoints, while `6 <= beverage_size < 17` includes 6 but excludes 17.
- Dictionary lookups use keys rather than list indexes; a score can be retrieved with `scores['Jill']`, typically without scanning every entry.
Chapters
- Indika Walimuni explains that previously unchecked missing-work settings had kept some grades inflated; the gradebook now shows actual scores.
- He reports that roughly 70% of the class is below 70% and urges students to address missing work.
- Students can arrange one-on-one help with Indika, contact one of three teaching assistants, or seek support through the CS department Discord.
- Students who still need to vote are encouraged to exercise their civic responsibility.
- The anagram problem takes two inputs, `word_one` and `word_two`, both strings.
- Its output is a Boolean: `True` when the words contain the same letters, and `False` otherwise.
- The example `silent` and `listen` illustrates that matching letters can appear in different orders.
- A necessary first test is whether the two strings have equal lengths.
- Words with different lengths, such as `listen` and a shorter word, cannot form an anagram pair.
- Equal length is a useful early rejection test, but matching lengths alone do not establish an anagram.
- Python has no string method that directly sorts a string; the built-in `sorted(word)` returns a list of its characters in order.
- Sorting `silent` and `listen` produces matching character lists despite their original order.
- List equality with `==` provides the Boolean result, and this approach also rejects unequal-length strings.
- Indika defines `is_anagram_pair` with two string parameters and returns whether their sorted character lists are equal.
- A function whose result is Boolean can use an `is_...` name to make its purpose clear.
- Printing calls with `silent` and `listen` and with a nonmatching pair demonstrates both `True` and `False` outcomes.
- The anagram plan names its inputs, creates a sorted character list for each word, and compares the lists.
- Indika recommends expressive, detailed step descriptions so the algorithm translates readily into code.
- Numbering algorithm steps communicates their order, just as sequential code runs from top to bottom.
- The class identifies `return` as a statement and `sorted_list_one == sorted_list_two` as an expression containing an operator and two operands.
- `sorted` is a built-in function, not a string or list method.
- The function’s formal parameters are placeholders in its definition; the values passed at a call are actual parameters.
- The exercise assumes the input words contain no spaces or punctuation; a broader solution would need to account for them.
- Conditional actions such as taking an umbrella when it rains provide an everyday model for branching.
- Words such as “if,” “until,” and “otherwise” express conditions or alternatives in ordinary language.
- Programming languages provide conditional execution because software often needs to take different actions depending on a condition.
- A flowchart uses ovals for start and end, rectangles for statements, and diamonds for decisions.
- A decision splits execution into true and false branches, which can rejoin after the conditional action.
- In the hotel example, an age of 68 satisfies the senior condition of being above 65, reducing a rate of 155 to 135.
- An `if` branch handles a condition that evaluates to true; `else` handles the remaining cases.
- The insurance example assigns a high rate when the driver is younger than 25 and a normal rate otherwise.
- A flowchart activity traces conditions and outputs, illustrating how branch paths depend on input values.
- The instructional animation identifies `None`, `False`, numeric zero, and empty containers such as strings, lists, and dictionaries as falsy values.
- Nonempty containers and other values are treated as truthy in Boolean contexts.
- Python evaluates `and` and `or` expressions from left to right and can stop once the result is determined.
- With `X = 1`, the false test `X >= 2` short-circuits an `and` expression before a division by zero is attempted.
- The guardian pattern places a safe check before a risky operation in an `and` expression.
- Checking `Y != 0` before evaluating `X / Y` prevents division by zero when `Y` is zero.
- The example shows why checking an unrelated condition first may allow execution to reach the dangerous division.
- Indika connects Boolean operations to logic gates in a CPU’s arithmetic and logic unit.
- An `if` statement expects a Boolean expression and executes its indented block only when that expression is true.
- A comparison such as `bonus == 10` evaluates to a Boolean and controls whether three items are added to an initial count of one.
- Python can test a list directly in an `if`: a nonempty list is truthy, while an empty list is falsy.
- The list example uses `else` to report the empty-list case when the `if` condition fails.
- When a task has more than two possible outcomes, `elif` adds another condition between `if` and `else`.
- Each `if` or `elif` branch runs only when its Boolean expression evaluates to true and earlier branches have not been selected.
- Indika recommends including an `else` branch to make the remaining case explicit.
- A decade exercise checks whether the number of years equals 10 and prints a different message otherwise.
- Problem wording such as “otherwise” signals that an `if`/`else` structure is needed.
- A range activity assumes a nonnegative integer and tests which values produce a specified branch.
- Python’s six comparison operators are `==`, `!=`, `<`, `>`, `<=`, and `>=`.
- The operators compare their operands and produce Boolean results.
- Comparison operators share a precedence level and have higher precedence than `not`, `and`, and `or`.
- When operators have equal precedence, evaluation is generally left to right, with exponentiation noted as an exception.
- Python supports chained comparisons such as `A < B < C` to check whether the middle value falls between two bounds.
- For school grades from 9 through 12 inclusive, the chained condition is `9 <= user_grade <= 12`.
- The exercise uses the chain in an `if`/`else` decision to report whether a student is in high school.
- A beverage size below 6 is classified as “too small.”
- Sizes from 6 inclusive to 17 exclusive are “acceptable,” expressed with `6 <= beverage_size < 17`.
- The final `else` handles sizes of 17 or greater and prints “too large.”
- Indika publishes a CS110A letter-grade programming activity in Module 9 and changes its due date to Saturday.
- The program must use the provided dictionary as input, and `for` loops are not allowed.
- Students are directed to review the types lesson for dictionary syntax and are told that dictionary knowledge is needed even though the core grading logic does not require it.
- The stated grade bands use 90, 80, and 70 as thresholds, with a courtesy policy that may award an A for scores of 89 or above.
- A dictionary stores key-value pairs, with a colon separating each key from its value.
- A lookup such as `scores['Jill']` uses the student name as a key and returns the associated score; dictionaries do not use list-style numeric indexes.
- Indika contrasts direct dictionary lookup, described as average constant time, with searching through a list, which can take time proportional to its length.
- The class closes with a reminder to use dictionary keys to retrieve values and to continue the branching module on Thursday.
Transcript excerpt
0:00 Good morning, guys. This is our agenda today. Um Okay, so we're going to go over this problem. Okay, one thing, guys, so this weekend uh I turn on a setting in your grade book that is now So, until until like this weekend, your grade was inflated. All right? If you missed the one and then you should like like you know by
0:48 the dead deadline, you usually cannot put a zero because you didn't submit it, right? So, now because until this weekend, that option was unchecked. So, that means you didn't get a zero even if you missed the deadline. So, I set that that way because sometimes we cannot finish a module by the deadline, module deadline, and then now we are not done with the module, but the due date is over, right? So, it's kind of was unfair for you to get a zero to a module that we haven't finished, right? So, that's why I kept that is open. But, we only have barely 6 weeks left in the semester,
1:35 right? So, that means we should now see the real score, the actual score, so that you know, if it is low, you take an action, right? So, I I checked that box and then I found that 70% of the class is underwater right now. Okay? So, you have a score less than 70%. That percentage is 60 to 70% of the class, which is a disappointment. Okay? So, take a look. Take an action. If you miss something, it should show now, right? And then you see the your respective grade. So, um we are here to help, right? So, don't ever forget that. And then you can
2:21 email me to set up a one-on-one session. Or we have three TAs for this class. You
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.