Activities: Week 7 (this is the week that includes the Mon-Tues of Fall Break)¶
- No class Monday because of Fall Break
- Remember that your Unix Problems are due immediately after fall break, on 10/18 at 11:59 PM, on Canvas. You can see the assignment: Unix Problems
- Before class Thursday:
- Read Sorting and anonymous functions
- Try all the exercises you can and try to formulate questions about concepts you find confusing/articulate ways of solving exercises in English.
- Make sure your Python installation is working properly.
- Read just the introduction to Unit Testing. (We will discuss this in lecture! You do not have to read the rest of this chapter beyond the introductory section; it addresses material you have NOT learned yet in this course. We will focus in more depth on that material later in the semester. But this week is the first time you will see the code for Unit Tests, so we will teach you how to understand the output you get from them when you run problem sets on your own computer.)
- If you have time, read Nested Data and Nested Iteration and try exercises in the section. We’ll be doing a bit of introduction to this topic today, before exploring it more next week.
- Before Sunday 11:59 PM:
- Save answers to Problem Set 5, below.
Your next DYU, Demonstrate Understanding 6, is due October 29 to give you time to get readjusted from the midterm, but you may get started on it at any time! You’ve already done all of the readings necessary to complete it.
Problem Set¶
fall_list
alphabetically and save the result in the variable sorted_fall_list
.
Write code to do two things: (a) sort the list food_amounts
by the value of each dictionary’s key "sugar_grams"
, and save the result in a variable sorted_by_sugar
.
(b) Net carbohydrates for each dictionary data structure can be found by subtracting the value associated with the key "fiber"
from the value associated with the key "carbohydrate"
. Sort this list of dictionaries by the value of each’s net carbohydrates, in order from the most to the least, largest -> smallest, and save the result, the properly sorted list, in a variable called sorted_net_carbs
.
HINT: You’ll at least need to pass a function to the key
parameter of the sorted
function to solve (a) AND to solve (b) – but for each part, you could solve it in a single line of code.
new_tuple_list
.
nl
. Write code to accumulate a list containing the second (as humans count) element of each sub-list and save it in a variable second_elems
.