CS 105 SUMMER – WEDNESDAY 7
What to talk about today? From Reading 10/11 Nested lists List sorting Modifying a list when looping through it From Reading 12 Keyword arguments and default values Also excel
Quiz 6 comments High level stats: Mean 83% - Nice job! Code Reading question seemed to go well Some adjustments: Programming questions – more attempts (but worth more points) so less questions on Q7. Two attempts on CDRD question on Quiz 7 Speaking of CDRD – that study I emailed
Practice Quiz 7 Has been up since Monday Another good reflection of the Quiz Wide programming net – pulling from HW 8-13 Still not harder excel stuff
Other course announcement stuff Reminder – ALL ZyBooks finished before reading day will get full credit, as will videos watched Plan to update grades – later today, Sunday, and reading day Please check your lab credit – if you know you're missing some, private Piazza post Will probably produce some help videos for next week, but won't mandate watching
Notes for next week Effectively like "finals" week plus a final week of class stuff Last Lab – review for finals Last Wednesday – review for finals and the bee movie script thing as promised Last homework? Not a homework – just doing the practice final at least once (when it is up!) ( Full homework score regardless of performance )
There were a LOT of MPs on html I found basic HTML tags confusing because they have multiple tags that render the same result such as <em>, <cite> and <italic>. Would it matter if I use <italic> instead of <cite>? They also have a lot of different tags which can be confusing. I would like to learn more about basic HTML tags as well as lists and tables as I found these sections to be the most confusing in the text as I discuss in the previous question. The muddiest point was probably the section about tables. In all honesty, the entire section was a little muddy. I know that most of what we learned here is pretty intuitive but there's just kind of a lot to keep in mind, especially in the tables section.
We don't test much HTML content - but If we have time today, I can take more questions Otherwise, I can answer other questions on Piazza – I don't mind Next lab goes into HTML quite a bit Finally, a more "gentle" intro than the book https://www.w3schools.com/html/
Couple quick MPs " I don't understand exactly how to use the .pop() function. How does it differ from the .remove() function?" Answer: .pop() removes by index location. .remove() removes by matching value "(in the videos) Solving some homework and practice quiz problems would also be a really awesome tool to help people understand stuff better" Answer: That's what I do on Wednesdays, partially…also office hours
One other quick MP Quote: "yuiyuyuy"
List Nesting
List nesting MPs "I believe list nesting was the most confusing concept" "I would like more details about when list nesting would be an ideal option for someone who is trying to get the desired output for a function, code, etc." "In this section I thought that list nesting was a little confusing, especially trying to identify what value would be returned by a given index."
List Nesting High level – a LIST of LISTS my_list = [["puffin", "muffin"], ["dog", 'frog"], ["bat", 'cat"]] What do you think my_list[1][2] is? How about my_list[1][0]?
List Nesting Need to access with multiple indices my_list = [[…],[…],[…]] my_list[#] – the whole list (row) at index # my_list[a][b] – the element in row a and position b No easy way to loop "by column"
Why nest lists? Use case 1) Like a table! [ A B C D ["A","B","C","D"], ["E","F","G","H"], E F G H ["I", "J", "K", "L"], I J K L ["M","N","O", "P"] ] M N O P
Why nest lists? Use case 2) like a battleship or chess board!!! (I'm sorry)
Why nest lists? Use case 3) for some sort of related data structure Example – a list of employees in different departments Department_list = [ ["Bob", "Karen", "Cindy"], ["Rachel", "Alice"], ["Beomjin", "David", "Kaye"] ] Each row is a department! …Can anyone think of a better option than nested lists?
Department use case – also a case for dictionaries! { "Department X": ["Bob", "Karen", "Cindy"], "Department Y": ["Rachel", "Alice"], "Department Z": ["Beomjin", "David", "Kaye"] } In the long run, it is up to you what data structures are best for a situation Largely – the same kinds of use cases as nested loops, since nested loops can operate over nested lists!
List Sorting
List sorting Some MPs talk about sorting with a "loop" In Python – don't bother Two kinds of sort Sort in place: my_list.sort() Make a sorted copy: my_copy = sorted(my_list) "Can python only do smallest to largest?" Nope! reverse= True can be an argument to either of them! Note - .sort() is not the same as .reverse()
Modifying a list while loop through it
What will be the data stored in my_list? my_list = [1,2,3,4] for num in my_list: num += 2 print(my_list) [1,2,3,4] A) B) [3, 4, 5, 6] B)
Lists are mutable, but… for loops don't access the memory – they fetch the values To modify a list, we need to either Use range 1. Use enumerate 2.
These loops both update the list by adding 5 to each element my_list = [1,2,3] my_list = [1,2,3] for i in range(len(my_list)): for i,val in enumerate(my_list): my_list[i] = my_list[i] + 5 my_list[i] = val + 5
Other list modifications Danger – adding to a list in a loop!!! for element in my_list: my_list.append(5) #How does the loop end?
Keyword Arguments and Default Values
Python arguments parameters are variables that hold the values of arguments when a function is called def a_function(param1, param2): … 5 "puffin" a_function(5, "puffin")
Python default arguments parameters are also keyword names for arguments – if we give them a default def a_function(param1, param2="red panda") "red panda" 5 "puffin" a_function(5, param2 ="puffin")
Python named arguments What happens here? def my_function(num1 = 5, num2, num3 = 10): print(num1+num2+num3) my_function(10, 10, 20)
Python argument fast rules keyword arguments are parameters which have a 1. default – optional positional arguments are parameters without a default 2. – data MUST be passed for the function to be called positional must come BEFORE keywords 3.
Excel By Example
Excel by example I downplayed the harder excel this summer For learning, let's look at the excel homework 13.2, 13.3
Identified Homework Problems 12.14, 12.15, 13.11, 13.13
Recommend
More recommend