Lecture Materials

Questions & Answers


Q: Will we get a certificate for this course with our grade on it? Or how will we prove that we have taken this class?

A1:  You can get a Stanford transcript. You will get a letter grade.


Q: Is it possible to change how we are graded(letter vs pass/fail) after the course finish?

A1:  Unfortanately no


Q: So we can treat the list-like values returned from dict.keys() like a list? Like we can use normal list functions with them?

A1:  Mostly yes! You can iterate over the list like with a for each loop or index into it

A2:  Oh oops. You cannot index into the list like object


Q: Is the quiz on monday the last one?

A1:  Yes the quiz on August 9th is the last quiz


Q: is it able to sort based on a function? so if you want to sort them in a wield order, you can define a function and tell the sort function to sort according to that function?

A1:  Yes! We will go more in depth into sorted later :)


Q: I keep getting emails about changing how the class is graded (either pass/fail or letter grades) is the pass/fail option not available for this class?

A1:  P/F is available for this class but you cannot change your grading basis after the letter grades come out. There is a deadline to switch the grading basis


Q: Is there a way to see what our grade is right now?

A1:  You cannot see your weighted average. If you have specific questions about your standing in the class, please stop by Juliette or Tara’s office hours


Q: Can you combine the reverse fuction with the sorted function to do reverse alphabetic order or from greatest to least?

A1:  Yes!


Q: is the sorted function case sensitive?

A1:  Yes it is :)


Q: can we somehow make text.split split a string depending on the commas?

A1:  You can add an argument text.split(‘,’) would split on commas.


Q: what is clean()?

A1:  It’s a function that we wrote for you. It loops through an inputted string and cleans off punctuation at the beginning and end of the string


Q: What was the key to the mystery encryption?

A1:  The encryption puzzle that we released a few weeks ago? I’m not sure but let’s ask Juliette at the end. If you were asking about something else, please follow up!


Q: how many times can python run in 1 sec? like C++ is capable of running around 1e8 times a sec

A1:  I’m not sure about the exact number but I know in general C++ is fastest than Python. We can follow up with Juliette at the end


Q: So the timing basically just tells how long it takes for the dictionary to search for something?

A1:  yeah


Q: What lectures and topics will be on the quiz?

A1:  The exact topics/lectures have not been announced. Unofficially, I would expect strings, lists, dictionaries, grids, drawing, and maps/lambas (the next topic). Quiz 2 is going to be a longer one than the first one I expect. But Juliette will officially announce what’s on it soon :)


Q: Do you prefer that we use is or == in our code?

A1:  Always ==. We never use is in 106A


Q: Hi! I hope you are doing good today! Not too sure if we we need to know this. But how do we add something to the middle of the list. .append() adds it to the end. How can we add things to the middle?

A1:  Hi Mikhail! I am doing very well and I hope you are too :) Yes, list.insert() which we’re going to talk about soon!


Q: What are some practical uses of timing?

A1:  Trying to figure out which algorithm is faster is how I’ve used it. But I’ve marked this for follow up at the end with Juliette because she might have a more through answer


Q: Is there a reason we don't use is in 106A? Does it not work in other languages, or for some similar reason? I'm just curious, I won't use is in my code :)

A1:  I honestly do not know. I’ll ask Juliette at the end!


Q: does that basically make lst like stack + queue + deque?

A1:  Yes you use pop to use a list like a stack (for other reading, a stack is a common data structure in other languages)


Q: so is extend like merging two lists?

A1:  Yep :)


Q: Just to clarify lst.pop gives the value at the last index right?

A1:  Yes, list.pop() removes the element from the end of the list.


Q: If there are two positions in a list with the same value will lst.remove always remove the first one?

A1:  Yes, it will always remove the first instance


Q: what is the difference between pop and remove?

A1:  Great question. list.pop() removes an element from the end of the list (or at a specific index if an index argument is provided). list.remove(elem) searches the list for the first instance of the elem and removes it. So list.pop() uses indexes and list.remove() uses elems


Q: the sort algorithm is O(nlogn) right?

A1:  Yes! More details at the end of this page: https://cs.stanford.edu/people/nick/py/python-sort.html


Q: can you use Min Max as variable names?

A1:  For style, you want all of your names to be lowercase (and words separated by _) so no because of the style requirements.


Q: Can you translated strings to integers? I feel like it would be relatively simple to create a new string and add the integer characters to it, but not the other way around.

A1:  If you have a string representation of a number (like, ‘3’) you can use int(str) to convert the string representation to an integer representation. I answered a question but maybe not yours so please follow up if you still have questions!


Q: is there a priority_queue data structure that support logn push and logn pop?

A1:  It seems like yes (but it will not be covered in this class). More info here: https://www.educative.io/edpresso/what-is-the-python-priority-queue


Q: Could you briefly explain count_target again?

A1:  Yes! count_target() takes in a list of ints and a target int and returns the int count number of times the target appears in the list (i.e. how many times the target appears in the list). To solve the problem, we created a count variable to track the number of times the target appears in the list. We then iterated through the nums in the list. If the num was equal to the target, we incremented the count. At the end, we returned the count variable (how many times the target appeared in the list). Please follow up if you have more questions!


Q: Why do we start off with best = nums[0]?

A1:  Great question! We had to initialize a variable to track the best (i.e. smallest value) in the list. Instead of initializing the value to say 0 (because this wouldn’t work if the numbers list was [5, 6, 7, 8] for example because the smallest number is 5 which is NOT smaller than 0). We said that the smallest (i.e. best) number is the first element. Then we kept on looking at the subsequent list entries to see if there was a smaller number


Q: does this still work if the first character is a digit?

A1:  Yes! (see the second example). I would recommend walking through it slowly with paper to understand why


Q: do we need the second take_next = false?

A1:  We have to “reset” take_next to be false if not we will grab everything


Q: Why don’t you need to say if take_next == True in line5?

A1:  take_next either is True or False. So this evaluates to if True or if False. This is just a stylistically better way to write if take_next == True


Q: Could you run the digit_decode without the first if statement so we could see what happens without it?

A1:  Yep! We only want to append the character if it came after a digit (everything will be grabbed without it)


Q: how many times can python run in 1 sec? like C++ is capable of running around 1e8 times a sec

A1:  Dictionaries are fast but in general Python is slower than other languages was Juliette’s answer


Q: can you explain the ordering, I don’t see it in the lexture notes?

A1:  Can you clarify what you are referring to?


Q: Sorry, the ordering of the if statements in the for loop.

A1:  If we switch the ordering we will add all the digits


Q: what does the second if statement do?

A1:  It updates our tracker to see if we should grab the next char in the string


Q: oh ok thank you!

A1:  You’re welcome!


Q: Can you explain the variable take_next?

A1:  take_next let’s us store whether we should take the next char in the string.


Q: after lecture, can you guys walk through the combine problem in the list2 excersize?

A1:  I can’t walk through this one today, but come to my office hours or Tara’s office hours.


Q: The one on the homework was where we got rick-rolled.

A1:  LOL