cs 105 summer wednesday 7 what to talk about today
play

CS 105 SUMMER WEDNESDAY 7 What to talk about today? From Reading - PowerPoint PPT Presentation

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


  1. CS 105 SUMMER – WEDNESDAY 7

  2. 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

  3. 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

  4. 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

  5. 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

  6. 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 )

  7. 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.

  8. 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/

  9. 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

  10. One other quick MP  Quote: "yuiyuyuy"

  11. List Nesting

  12. 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."

  13. 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]?

  14. 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"

  15. 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

  16. Why nest lists?  Use case 2) like a battleship or chess board!!!  (I'm sorry)

  17. 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?

  18. 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!

  19. List Sorting

  20. 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()

  21. Modifying a list while loop through it

  22. 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)

  23. 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.

  24. 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

  25. 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?

  26. Keyword Arguments and Default Values

  27. 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")

  28. 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")

  29. Python named arguments  What happens here?  def my_function(num1 = 5, num2, num3 = 10):  print(num1+num2+num3)  my_function(10, 10, 20)

  30. 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.

  31. Excel By Example

  32. Excel by example  I downplayed the harder excel this summer  For learning, let's look at the excel homework  13.2, 13.3

  33. Identified Homework Problems 12.14, 12.15, 13.11, 13.13

Recommend


More recommend