Topics: Object Oriented Programming: dunder methods, examples We start with a review of classes and methods from last lecture. Class vs. instance of a class. All review for me, of course, but I like to observe how they teach it. Dunder methods review. Why OOP and bundling the data in …
Topics: Object Oriented Programming: data abstraction, class def, class instances, methods More review for me. I don’t mind reviewing though. We start by defining an object, along with examples. Advantages of OOP Bundle data into packages together with procedures that work on them through well-defined interfaces Divide and conquer …
Topics: Recursion: Fibonacci, Fibonacci with a dict, recursion on non-numerics, recursion on lists, Towers of Hanoi (extra) We start by reviewing fibonacci and tracing through the function call graph. Recursion in general is review for me, I still think this lecture is good for me to digest. After doing another …
Topics: Recursion: iteration vs. recursion, inductive reasoning Recursion is review for me. I like the example she gave with the student asking professor, TA, and LA to regrade. Big idea: “Earlier” function calls are waiting on results before completing. Went over some more examples of recursion. When to use recursion …
Finished the problem set in about an hour. It was a good exercise. Here is my solution along with test case results: My solution: # Purpose: Check for similarity between two texts by comparing different kinds of word statistics. import string import math ### DO NOT MODIFY THIS FUNCTION def load_file(filename …
Topics: Dictionaries: keys, values, mutability, iteration over a dict, examples This is review for me, I am familiar with dictionaries. I guess one new thing I learned is that dictionary keys must be immutable or technically hash-able objects. Although in practice this is obvious.
Topics: Exceptions, assertions Introduced to the try/except code blocks, with some examples. Also introduced to assertions, as a way to program defensively. I sort of forgot about assertions so this is good review. I will look to use them in my future code. They are good for enforcing invariants …
Topics: More Functions as Objects, Keyword Arguments, Default Arguments, Debugging: glass box/black box testing, examples List comprehensions are review for me. Default parameters are also review. Functions can return another function. Why bother returning functions? Code can be rewritten without returning function objects Good software design Embracing ideas of …
Topics: Aliasing and cloning Going over some operations on lists, including .clear(), .pop(), del() and .remove(). Iterating over a list as you are mutating the list can lead to unpredictable behavior. Takeaway here is to be careful when mutating a list while iterating over it. Consider using a copy. = sign …
I was able to complete this problem set in just under an hour. It was good practice. Will show my code then the result of running the unit tests. My solution: import random import string # ----------------------------------- # HELPER CODE # ----------------------------------- WORDLIST_FILENAME = "words.txt" VOWELS = 'aeiou' def load_words(): """ returns: list, a list of valid …