Lecture Materials

Questions & Answers


Q: Will we be doing drawing in sections?

A1:  Yes!


Q: Can contest submissions only be graphical drawings?

A1:  Whatever you want :) Drawing, data visualization, games etc


Q: can you use algorithms outside of this class?

A1:  Yes but we are judging based on what we taught in 106A


Q: How do you make a graphical drawing like that one?

A1:  Assignment 5 and 6 can give you some ideas :)


Q: if the quiz is on monday August 9 then does that mean there is no class on that day?

A1:  Yes, no lecture that day


Q: If two projects scored the same but one was written with more 106A material then would the 106A one win?

A1:  Yes, we judge based on using 106A material


Q: How will your code be graded if it has no graphical images or animations? Or it has no “aesthetic merit”?

A1:  This could fall into the Algorithmic sophistication category


Q: can you make a piece of code that solves a particular problem?

A1:  I believe so but will confirm with Juliette at the end :)


Q: What was Sarah’s 106A project? :)

A1:  I didn’t do one :/


Q: For the people who don’t win will they still get some EC of some type? :) If so how many points roughly?

A1:  I believe only the winners get EC but will confirm with Juliette at the end


Q: when you pass in a list or dict as a parameter, does it copy the list or dict or does it pass a pointer?

A1:  It does not pass a copy it in a sense passes a pointer (but Python doesn’t have pointers like C++/C/Java). If you modify the dictionary in the helper function you are modifying the actual dictionary (this is because lists and dicitonaries are mutable and string/ints are immutable).


Q: can a key point to None?

A1:  Yes :)


Q: So d would now equal {'a': 1, 'b': [1, 2, 3, 4]}? I just want to make sure I'm understanding this

A1:  Yep totally on it :)


Q: d[‘b’] = [1, 2, 3, 4] because the key b is assigned the list right ?

A1:  Yes :)


Q: why does hosts[host] give back a list of users?

A1:  Great question! When we built our dictionary called hosts, we decided that they keys would be the email host names (i.e. ‘foo.com’) and the values associated with the keys is a list of the users under that host name


Q: how do we get back a list of users if we never put users in the dictionary?

A1:  We are putting the users into the list right now :) The values in this dictionary is a list of the users under the host name


Q: Why can we say users.append(user) when ‘user’ hasn’t been defined yet? Does ‘users’ account for defining ‘user’ as well?

A1:  We just defined users = hosts[host]. The values in the hosts dictionary is a list


Q: in the contest will style/comments be taken into account?

A1:  Style is part of the evaluation but functionality is the main component. We should be able to understand your code and it’s a good habit to always code with good style. Here’s what the graphics contest handout says: “In both categories, programming style will be part of the evaluation (so don't submit horrendous code), but the functionality of your program will be the most important aspect for judging. “


Q: Oh nevermind the last question, I see where user is defined now

A1:  Okay great :)


Q: Would you have to do the initialization step for the users?

A1:  We recommend using decomp by var when working with nested dictionaries but technically hosts[host].append(user) would functionally work


Q: what would happen if you skipped “if host not in hosts:”?

A1:  We just demoed this live. You get and error because you are appending to a list that does not exist


Q: I don’t understand users and user can you explain that?

A1:  Yes! user is a variable that stores the user name from the string email (i.e. abby@foo.com; user = abby). users is decomp by var. We decided to call the value in the dictionary users since it’s a list of the users who have that host email. Please follow up if you still have questions!


Q: Sorry can you briefly explain that again?

A1:  Yes, which part is helpful?


Q: memory example

A1:  Got it!


Q: just a question, can you use recursion in the contest?

A1:  I believe yes but that would not give you a better likely hood of winning. We are judging based on your use of 106A material. But will confirm with Juliette at the end


Q: How come we don’t need to write “if user not in users:” like we did for the hosts in the dictionary?

A1:  Great question! We had to say if host not in hosts because if the host is not in the dictionary, then there is no list to append the username to (so we have to associate the host name with an empty list to hold the user names). We don’t need if user not in users because we do not care about duplicate usernames in the users list


Q: is there a way to reset the list like memset in C++?

A1:  Not really.


Q: can you explain lines 3-6?

A1:  Yep! Demoing now :)


Q: What situation woudl food not be in foods?

A1:  If it’s a new food that hasn’t been seen yet. Like the first time donut is seen it is not in foods


Q: how to make a two dimensional dict?

A1:  Nested dictionaries are like 2d dicts (instead of the values being lists they will be dicts) We will cover this next time.


Q: how to read one int at a time

A1:  f.readline() give you one line at a time. or with open paired with for line in file


Q: of all the file reading methods is there one method that is stylistically preferred?

A1:  We like with open (filename) and for line in file but sometimes you need f.readlines()


Q: how to read inputs entered in terminal after you run the commend?

A1:  You can use input()


Q: I mean stdin like in c++

A1:  got it :)


Q: Are we compared to students in CS106B, or is this only for CS106A?

A1:  Nope this is just for 106A students :)


Q: do you get points if you just use for loops but you create something very complicated with it like dijkstra, kruskal etc

A1:  If you use 106A material to make complicated algorithms we would love to see it :)


Q: quick question. For s.find how can u return a bool? Like I want to find the first alphabetic character using s.find

A1:  s.find() always returns a number. Either the index of the substring or -1 if it’s not in there. So you could use if index == -1 return false


Q: If I win the contest, could you write a recomendation letter for my admission to stanford?

A1:  Perhaps :)


Q: Is there something like struct in python?

A1:  Not that I know of, but classes are pretty intuitive in Python so you can use a class instead.