Week 8 Reflections
Lists, Dictionaries, and Classes
Due: 11:59 PM on Sunday, March 28
Weekly Recap
Congratulations! We have finished the eighth week of class. Since our last reflection, we have worked on two important topics. We learned about several different ways to combine and organize data in Python, such as using lists (to sequentially order information) and dictionaries (for associating information as key:value pairs). We have also started discussing object-oriented programming, which allows us to design our own data types through classes. We have already seen several classes this semester, including Picture classes in Lab 3 (from picture.py) and Lab 4 (from picture2.py), as well as strings, lists, and dictionaries. Classes define both the data stored in a data type (through instance variables) and actions we can take with the data (through methods). For example, the string class stores characters and allows us to perform operations on the strings (converting them to lowercase, removing characters, reversing the string). Similarly, the Picture class stores pixel information at different locations, and we can perform operations like getting or changing the color at a particular pixel. To recap this week:
- On Wednesday, we finished our discussion about dictionaries. Dictionaries are a special way of storing collections of information, like lists, except we can index that information using strings or other data types instead of only numbers (in contrast, lists can only index based on the position of information in the list). We saw that dictionaries can be used for applications such as storing information about our friends (e.g., their favorite colors, their weekend plans), counting how many times words appear in a piece of literature, and calculating the frequency of words in emails for spam filters.
We also introduced object-oriented programming and constrated it with the proceedural programming that we've been using so far. Up to now, procedural programming creates programs that behave like "scripts" -- the program performs one command after another until it reaches the end. Object-oriented programming, on the other hand, focuses on creating representations of entities that exist in the real-world (using classes), then instances of those entities (called objects) interact with one another (through special functions called methods) until the problem is solved. - On Friday, we introduced the foundations of object-oriented programming: how we represent entities using classes, which consist of (1) instance variables to store information unique to different instances of a class (e.g., all students have names, but different students have different names) and (2) methods, which are functions that perform actions. We explored examples of classes in different real-world examples, such as students registering for courses, online purchasing, and card games. We also discussed how to create classes with their instance varaibles and methods, and how to create instances of classes (also called objects) that represent specific entities in the program.
- In lab, we practiced using lists, files, and dictionaries by building concordances for pieces of literature by tracking on which lines each word is used in the literature.
Your Reflections
In this activity, you have the opportunity to reflect on your own experiences and connections with computer science. In particular, you should answer the following three questions:
- What did you learn this week?
- What would you now like to know more about?
- What connections can you make between something from class this week and your life (e.g., your personal interests, your future goals, your other classes, or society at large)?
You should type up your answers to the above questions in a single document using your favorite word processing software (e.g., Microsoft Word, Apple Pages, Google Docs), save the file as a PDF, and upload it to Gradescope under the assignment "Week 8 Reflections". Each answer should be at least one paragraph of 3-5 sentences (instead of 3-5 sentences total across all answers).
At the end of your document, please indicate that you have followed the honor code on this assignment by writing:
I have adhered to the Honor Code in this assignment.