Lecture Materials

Questions & Answers


Q: What topics and lectures are covered on the second quiz? :)

A1:  There hasn’t been an official announcement yet but pretty much everything that wasn’t on quiz 1: Strings, Lists, File Reading, Drawing, Dictionaries, Map/Lambda/Sorting. It’s going to be a big one! I would start studying early :)


Q: Just curious… will this class cover how to make classes and objects in python?

A1:  Yes! I believe we are doing classes in Wk 8 (maybe end of wk 7)


Q: what does "map" do?

A1:  Map loops over a list or list-like collection and calls the function (given as a parameter) on each elem in the list and then returns a new list :)


Q: Could we and should we use map(lambda...) for assignment 6 warmups?

A1:  You do not need map/lambda for the assignment 6 warmups :)


Q: Did we make the line to return a list?

A1:  We have return before our map call: return map(lambda s: len(s), strs)


Q: Don't you need list(map....)

A1:  We only use list() when we need an actual list. Frequently we will use map without list(). (You need list() in the interpretor)


Q: Since there’s a lot more covered on quiz 2, do you suspect it will be longer and with more questions?

A1:  Yes, I do.


Q: If I missed my section this week do I just randomly join any other section using the zoom link? I don’t seem to find the email contacts of section leaders to notify them in advance.

A1:  Yes! You should attended another section time. We intentionally do not release the SL names so that you have to email your SL the name of the SL running the section to get attendance credit. So: Email your SL to let them know you will/have missed section -> Attend another section time -> Let the SL know you are a guest -> Participate in section -> Email your section leader letting them know who’s section you attended.


Q: Can you use a defined function in a lambda?

A1:  Great question! I believe you can because in the lens() example we called len(s) on each elem in the list


Q: what do we use to study for the next quiz?

A1:  Great question! The experiemental server problems are great practice. The extra section problems that are not covered in section are also great practice. Making sure you understand your homework submissions (the concepts behind the problems and the feedback you received from your SL). Soon, we will also release practice material. But in the interim, I would recommend solving extra problems and making summary sheets for the different topics (strings, lists, dicts etc). On my summary sheets, I put the different commands/when to use them and common patterns encountered (like for drawing I would put the x_add pattern).


Q: For this week’s homework 6, which lectures does it cover? :)

A1:  Through lecture 21 ethics :)


Q: Is the next quiz our final "exam"?

A1:  The next and last quiz is on Monday, Aug 9th at 1:30pm PT unless you have an academic/time zone conflict in which case you should reach out to head TA Tara to arrange another time to take the quiz :)


Q: why do you add another point at the end of map(lambda point: point[0] + point[1], points) <— this one

A1:  Great question! The map() function has two parameters: the first is the function and the second is the like/list-like collection. So in this example, the stuff before the comma is the function (here a lambda function) and the thing after the comma (points) is the list to apply the function to


Q: What will we be doing after the quiz? Will there still be lectures?

A1:  There will not be a lecture on Mon, Aug 9th


Q: What will occur in the three days following the quiz?

A1:  More bonus material! The very last day is typically a look at how far you’ve come and here’s what you can do next type class (this would be Thursday). On Tues and Wed we are covering extra stuff. I’m not sure exactly what is on the agenda but likely list comprehension/classes/other cool stuff :) Juliette will announce closer to the time


Q: Will there be lectures on Tueday, Wednesday, and Thursday the week of the quiz?

A1:  I believe yes. If any of them are canceled we will make an announcement


Q: why do we say point after lamda?

A1:  Great question! It’s a variable name. Lambda vs Def can help understand


Q: Does the second map parameter have to be a list?

A1:  Yes or a list-like collection :)


Q: why do we say “lamda point:” ?

A1:  We are given a name to our elem :)


Q: What do we do if we cannot meet with Tara or Juliette during OH but wish to know our grades? Do we email them?

A1:  Yes, reach out to them via email. To clarify, Juliette and Tara are not going to give you % but can provide more insight into how you stand overall


Q: So does lambda make a function that we can call again later?

A1:  No. Lambda does not define a function that you can call later. You can use the same code again but you have to put it in the spot where you need it. It’s not like a helper that you can call whenever


Q: Will we also be learning about list comprehension during the bonus material after the quiz?

A1:  Probably! I’m not sure what material will be covered during the end of wk 7 vs wk 8 though


Q: What’s the difference between map and lambda?

A1:  Great question! map() is a function that takes in a function/lambda and a list and applies the function to each elem of the list and returns a new list. map() is sort of like a for each loop. lambda is an anonymous function. You can (and will) use lambdas outside of the context of maps. Lambdas are a way to define a function without formally defining a function.


Q: Will we still have section on the 8th week or is the 7th week our last week of sections? :)

A1:  Great question! I actually do not know. I will ask Juliette at the end :)


Q: Is there a way to do min_x in only one line? Like return min(xs) = …..

A1:  Yep :) see the solution on the slides


Q: What could we do with the information of where the code is in our ram? Also, where does the word "lambda" come from?

A1:  Can you clarify your first question? For your second queston, I’m not sure why they are called lambda. Will ask Juliette at the end :)


Q: for each individual tuple, can you redefine the greater smaller than operator, so when sorting, it will just sort according to the operator?

A1:  In a sense. The sort() function is very customizable. You can decide what value to sort by using lambdas and what order things should be sorted. I answered a question but maybe not yours so please follow up if you have more questions!


Q: can you use lambda on the homework6?

A1:  Yes, you are free to use lambdas on assn 6 if you want to. I don’t think there’s really an opportunity to use it though.


Q: By redefining the operator, I kind of mean that you can just use greater and smaller operator in anythin, like in if statements and etc.

A1:  Right no. You can decide if you want it to sort in ascending or descending order but you don’t use > or <


Q: What problems on the experimental server can we use for our warmups and biasbars?

A1:  On the assignment handout, they provide a link to the relevant section. Your warmsups are the dict3hw problems in this link: https://wopr-service-qbrbcbuzwa-uw.a.run.app/#dict3hw Biasbars is done in Pycharm


Q: Can you re-explain what key= does?

A1:  In the default sorted(), you just provide one parameter. You can submit an optional parameters if you want it to sort by a different method than the default. key= allows you to custom sort :)


Q: what does the key parameter do without a lambda

A1:  It has to be a function either a def function or a lambda :)


Q: What other problems on the experimental server can we use as a reference for our warmups and biasbars?

A1:  Great question! The dict and lists problems are helpful so like dict 4 list 2 etc. I’ll ask Juliette at the end if she has specific recommendations :)


Q: is every character represented by a number?

A1:  Yep :) If you want to know more, here’s a table: https://www.utf8-chartable.de/


Q: so by doing the lower case version in the sort we are no longer case sensitive?

A1:  Yes :)


Q: can you make something not sortable sort by using lambda or def?

A1:  mmm I don’t think so. In case I’m misunderstanding, can you clarify your question?


Q: What type of questions will be on the quiz? Something like crypto or sand? Or like the previous quiz?

A1:  Great question! The quiz will not have problems as hefty as crypto or sand. The problems are generally around the difficulty of a section problem (it needs to be solved in a few minutes not a few hours). Soon, practice materials will be released that may give you more insight


Q: how do you know that the number is the first index in pair?

A1:  The number is the second index (1). The person who wrote the list of tuples decided that a letter would be first and number would be second. I answered a question but maybe not yours so please follow up if you have more questions!


Q: When you put key=lambda pair: pair [1], how does the program know were accessing the pair at index 1 when we can choose any variable name instead of pair?

A1:  When we said, lambda pair we define our variable name as pair. We could have said lambda pizza : pizza[1]. The computer doesn’t know but we do :)


Q: if you define like a class or something that don’t have a default way of sorting, and you want to sort it based on some aspect of the class, how would you sort that?

A1:  You would use custom sorting with key=. If you are making a custom object you have to use custom sorting :)


Q: Can we slice sorted_items

A1:  We should be able to since it’s a list :)


Q: can you do key = lambda before hand and then just pass in key as a variable? Or do you have to define key in the sort?

A1:  key= lambda is just saying that you want to include another paramter. key does not store the lambda. You have to redefine the lambda each time you call sorted. If you didn’t use lambda you could write a standard def function and call that multiple times


Q: What do the two vars in the for loop do? Does it loop over both of them?

A1:  Which for loop are you referencing?


Q: Can we slice tupels?

A1:  Yes!


Q: Is the last section today or next week?

A1:  No, you will have section this week (wk 6) and wk 7 but no section in wk 8. So 2 more sections :)


Q: do we get HW on this topic or is there no more HWs after HW 6?

A1:  This will be on the quiz. But no more formal homeworks after assn 6


Q: The second quiz doesn’t cover any of the material on the first quiz correct? :)

A1:  Yes, it’s not cummulative so no Bit or Images. Fundamentals like loops, variables etc will show up


Q: When will we recieve the quiz 2 practice materials?

A1:  On Monday or Tuesday of next week :)


Q: Do we have drawing on the quiz?

A1:  Yes!


Q: do you know how long the quiz will be in minutes and number of questions?

A1:  You will not know this in advance


Q: Are their OH for Juliette and Tara week 8?

A1:  To be determined