May 20th, 2020
Q: Hello. The link on the previous class's slide isn't working. Could you confirm?
A1: It’s working for me: http://web.stanford.edu/class/cs106a/lectures/18-NestedStructures2/18-NestedStructures2.pdf
Q: how are we today!
A1: Thinking about colors more than I thought I would be!
Q: could we get help from lair for our project?
A1: We might not be able to provide specific advice, but we can provide some general guidance. We’ll probably prioritize assignment help, though
Q: The link of slide is "http://web.stanford.edu/class/cs106a/lectures/18-NestedStructures2/18-NestedStuctures2.pdf", NestedStuctures2.pdf is wrong. St"r"uctures is correct.
A1: Where are you finding this link from?
Q: How are tuples different from dictionaries?
A1: They don’t have keys and values, they’re ordered, and index
Q: I find here. http://web.stanford.edu/class/cs106a/schedule.html
A1: Cool, thanks, I’ll fix that
Q: Are print functions tuples?
A1: No - what makes you think they would be?
Q: how can you know it is a tuple and not a list when it shows up in someones code (by the name)?
A1: ( instead of [ !
Q: about indexes, can we mix negative index with positive ones ? As use the both of them in the same function ?
A1: Yep
Q: How do max and min work on strings?
A1: They return the alphabetically last and first character, respectively
Q: what do max(), min() and sum() do for non-numeric elements?
A1: It depends on the type of the elements - strings, for example, will be compared alphabetically. We’ll talk more about that in a bit
Q: what happens if you sum stanford
A1: Python will complain because it doesn’t know how to add 94305 to a string
Q: How do you create a very large tuple if you cannout use functions like list.append()? do you have to write out the tuple manually?
A1: Yes - you can also convert a list to a tuple (we’ll talk about that in a bit)
Q: can you put tuples in json, if theyre imutable anyway, might as well put them with the othere data
A1: Yep, you can put them in json files
Q: does it change the values of chartreuse if you return rgb_tuple?
A1: You’d need to store it back in the original variable (like a string or int)
Q: In the date example, the tuple does not have a name..how do yu assign a name to a tuple that has both the "coordinates" like dd/mm/yyyy and the values?
A1: Just store it in a variable with the appropriate name
Q: What is the additional usefulness of returning a tuple from a function when you could return a list and access the individual elements of the list?
A1: Also, you can access individual elements in a tuple too
A2: its the default that if you return multiple values it becomes a tuple
Q: Why doesn’t day, month, year have to be in parentheses when it is returned?
A1: Tuples can also be defined by the comma! The parentheses are just a stylistic convention that we don’t use when returning
Q: Is that Mehran's birthday?
A1: yep :)
Q: does the list function work on other things as well? (Say a string?)
A1: Yep
Q: does it work the the other way as well, so list = list(string) and string = string(list)
A1: So str(lst) won’t stick everything together - you’d need to use “”.join(lst) for that
Q: in the slide that mehran just covered, where we loop through key/value pairs as tuples
A1: Answering in your next question
Q: do we have to define what key and value are? (sorry question got cut off)
A1: No, the for loop defines them for you.
Q: how you make tuples in the “value part”. In other words, how to make something in your dictionary be a tuple?
A1: Just by writing it out in your code i.e dict[key] = (1, 2, 3)
Q: Is there a scenario where a tuple can do something a list cannot? (Where would we use a tuple rather than a list?)
A1: We just talked about it - a tuple can be used as a key in a dictionary, or is used to represent a group of variables that represent one thing (i.e. a point with x, y values)
Q: and what about when we want to make it decreasing?
A1: live answered
Q: What if a word is a mixture of upper and lower case?
A1: the comparisons are done on a character by character basis