Lecture Materials

Questions & Answers

Q: when do we receive our diagnostic grades?

A1:  live answered

Q: Sorry some of us might have missed it, when do we recieve our diagnostic grades?

A1:  By Wednesday’s class

Q: Can you run the program through the console?

A1:  Not easily! You should use the terminal for that.

Q: Can you have lists within lists?

A1:  Can you have lists within lists?

A2:  Yep! We’ll get there in the next lecture

Q: Had some confusion with 'Ghost' in Assgn 3 - if we use load_images() and that returns a list of picture elements, can we pass element numbers into function parameters?

A1:  You shouldn’t need to do anything with lists for ghost

Q: Did we get grades for the assessment? If so, where are they posted?

A1:  They’ll be released by Wednesday’s class.

Q: Is empty_list == None?

A1:  No

Q: Does the assignment of a replacement element need to be the same type as the element it was replacing (string to string, vs. string to float)

A1:  Nope! Good question. In general, though, you usually won’t have lists with multiple different types.

A2:  Does the assignment of a replacement element need to be the same type as the element it was replacing (string to string, vs. string to float)

Q: how can length be -1 ?

A1:  length - 1 means 1 less than the length of the list, not length=-1

Q: Will a for loop with a range of 0, simply just not execute the for loop?

A1:  Will a for loop with a range of 0, simply just not execute the for loop?

A2:  Yep

Q: Why isn’t len (emptylist) not equal to none but rather zero?

A1:  len returns how many elements there are in the list - there are 0 elements in the list!

Q: why don’t the negatives start from 0 ?

A1:  You can kind of imagine the negative index as how far back from the end of the list you’re going. The last element is at length - 1, so you start off at -1 with negative indices.

Q: can lists be edited outside the loop like a google doc? or a pixel

A1:  Yes! Great question, they’re also stored like URLs

Q: Are we allowed to use an underscore in a list name?

A1:  Yep

Q: can the append work for str and floaps?

A1:  Nope, it’s just for lists

Q: what if i appended a 25? does it still go at the end would i get error

A1:  You can append whatever you want

Q: Do lists of integers need to go in increasing numerical order?

A1:  Nope!

Q: I mean, lists of str and floaps

A1:  Oh, yep!

Q: can .append add elements between existing elements instead of at the end?

A1:  There’s another function for that called .insert

Q: can we add something to a llist but not to the end, maybe to the middle?

A1:  Yes, there’s a function called .insert

Q: how is the order, then? because the a came first now

A1:  It’s just the order that you append to it

Q: what are the names of the things that come after the . (For example alist.append, what is append called? A function?)

A1:  Methods! Saying ‘functions’ is also fine

Q: Can we append multiple elements at once_

A1:  Not in one fell swoop, you’ll have to call it multiple times. There are other functions to do this but we’ll get there!

Q: Can you append multiple elements to a list? Like alist.append(10, 20)

A1:  Not in one fell swoop, you’ll have to call it multiple times. There are other functions to do this but we’ll get there!

Q: Are empty lists often used like a variable that counts or keeps track of something (tally)

A1:  Yes! You’ll see some examples of this soon.

Q: what’s the difference between variable.fun() and fun(variable)? Is there any rules on how to remember which one to use?

A1:  fun is when you’ve defined your own function, and .fun() is for a method that comes inbuilt to a particular variable type (like append)

Q: the removing is just for the last value, right? What about removing more things?

A1:  You can’t remove multiple things at tone time using .pop

Q: when it gets returned to x, does it all store in x or does it replace the value of x?

A1:  .pop() returns the element that got removed

Q: Can you find where exactly the element is in the list? Like the index or indices?

A1:  We’ll get there soon enough!

Q: is range(n) a list ?

A1:  ish! It doesn’t store all the numbers at once (that would take up a lot of space) so it gives each number to you one by one. You can convert it to a list, though. Good question!

Q: are we going to have a reference sheet for lists?

A1:  http://web.stanford.edu/class/cs106a/pythonreader/lists/

Q: can you do if list[4]: # do something in order to see if there is an element in position [4]?

A1:  Nope, list[4] would crash if there isn’t an index 4. You’ll need to check the length of the list.

Q: diff between .remove and .pop?

A1:  .remove removes a particular value, .pop removes whatever is at the end of the list.

A2:  pop takes an index, remove takes an element

Q: Can we remove elements using certain parameters such as elements being greater or less than others?

A1:  short answer: not using the standard list library

Q: How can one make it append in numerical order? Rather than just putting one list after the other?

A1:  You have to sort the list first (we’ll talk about this later)

Q: Once the second_list is extended into the first_list, will second_list retain its original elements or will it be an empty list since all it’s elements are transferred into first_list?

A1:  It’ll still have its original elements in it

Q: Will fantasy = actual_jedi not work?

A1:  it works but then those two tags refer to the same list (so changing one will change the other)

A2:  Will fantasy = actual_jedi not work?

Q: Can we do list_1 = list_2 instead of list_1 = list2.copy()?

A1:  Yes, but then changing one list woudl change the other too

Q: What would happen if you tried to get the max of a list that only includes strings?

A1:  It compares strings alphabetically

Q: can extend be used to simply add 1 element

A1:  Yes, if you put it in a list, but that’s a little roundabout

A2:  yes

Q: would newlist = oldlist produce the same functionality as newlist = oldlist.copy()?

A1:  no. In the first, both lists refer to the same list.

A2:  No, changing one list would change the other.

Q: What happens when you sum a list of letters/non-numbers?

A1:  It would concatenate all the strings, I believe

Q: For the for-each loop, do you have to first assign the variable to a value (like elem in this example or pixel) before using the for-each loop?

A1:  Nope, the for loop defines it for you

Q: Is mutable the same thing as “pass by reference” in other languages?

A1:  It’s pretty similar, yeah

Q: How does this affect the idea of ‘local’ lists? (like local variables)

A1:  The URLs are local, but the lists (the webpages) aren’t!

Q: can you get the new list by a return function?

A1:  Can you clarify what you mean?

Q: if you want to show new num_list can you return num_list?

A1:  What do you mean by ‘show’?

Q: If you wanted to change the list in place using a for each loop, could you assign list[elem] = elem +=1?

A1:  Yep!

Q: what does primitive mean again?

A1:  It’s a simple variable like an int or float, which doesn’t get passed by reference!

Q: What is a primitive type?

A1:  A simple variable like an int or float, which isn’t passed by reference

Q: What would be the difference between saying for value in list vs for elem in list?

A1:  No difference, except the name of the variable

Q: why do you have to pass in a constant EXTRA CREDIT. can’t every function already see it?

A1:  Great question! It’s mostly a question of making this function more generalizable

Q: For the animation class last week - how can we export our animations in a video format?

A1:  Unfortunately, there isn’t an easy way - you might want to try taking a screen recording.

Q: would it work if you didn’t pass in EXTRA CREDIT? would it be able to see the global constant and still work?

A1:  You’d have to refer to it as EXTRA_CREDIT and not extra_credit, but yep

Q: How come a return list was not necessary at the end of the get_extra_credit function?

A1:  Because the list was passed in by reference, so the changes are made in place.

Q: why in give extra credit do we not have to have a line to return the scores? Are lists automatically returned from functions when we modify individual elements?

A1:  live answered

Q: What can we type into terminal to stop a program that is running?

A1:  live answered

Q: is there a way to paramatrise pixel.blue? say a function that takes function(color) and returns pixel.color

A1:  live answered

Q: What is a primitive?

A1:  live answered

Q: Can we use lists in assignment 3? I think my code could be better if i did.

A1:  live answered