Adapted from slides by Marty Stepp and Stuart Reges

Slides:



Advertisements
Similar presentations
Copyright 2010 by Pearson Education Building Java Programs Chapter 7 Lecture 17: Arrays for Tallying; Text Processing reading: 4.3, 7.6 (Slides adapted.
Advertisements

CSc 110, Autumn 2016 Lecture 9: input ; if/else Adapted from slides by Marty Stepp and Stuart Reges.
Adapted from slides by Marty Stepp and Stuart Reges
CSc 110, Autumn 2016 Lecture 26: Sets and Dictionaries
Adapted from slides by Marty Stepp and Stuart Reges
Adapted from slides by Marty Stepp and Stuart Reges
CSc 110, Autumn 2017 Lecture 16: Fencepost Loops and Review
CSc 110, Spring 2017 Lecture 12: Random Numbers
CSc 110, Autumn 2017 Lecture 17: while Loops and Sentinel Loops
Adapted from slides by Marty Stepp and Stuart Reges
Adapted from slides by Marty Stepp and Stuart Reges
CSc 110, Autumn 2017 Lecture 19: While loops and File Input
CSc 110, Autumn 2017 Lecture 20: Line-Based File Input
CSc 110, Spring 2017 Lecture 29: Sets and Dictionaries
CSc 110, Autumn 2017 Lecture 21: Line-Based File Input
Adapted from slides by Marty Stepp and Stuart Reges
CSc 110, Autumn 2016 Lecture 27: Sets and Dictionaries
Adapted from slides by Marty Stepp and Stuart Reges
Adapted from slides by Marty Stepp and Stuart Reges
CSc 110, Spring 2017 Lecture 14: Boolean Logic and Midterm Review
CSc 110, Autumn 2017 Lecture 24: Lists for Tallying; Text Processing
CSc 110, Autumn 2017 Lecture 18: While loops and File Input
Adapted from slides by Marty Stepp and Stuart Reges
CSc 110, Autumn 2017 Lecture 23: lists as Parameters
CSc 110, Autumn 2017 Lecture 37: searching and sorting
Adapted from slides by Marty Stepp and Stuart Reges
CSc 110, Autumn 2016 Lecture 13: Random Numbers
CSc 110, Spring 2017 Lecture 28: Sets and Dictionaries
CSc 110, Spring 2018 Lecture 32: Sets and Dictionaries
CSc 110, Autumn 2017 Lecture 31: Dictionaries
CSc 110, Autumn 2017 Lecture 30: Sets and Dictionaries
CSc 110, Autumn 2016 Lecture 12: while Loops, Fencepost Loops, and Sentinel Loops Adapted from slides by Marty Stepp and Stuart Reges.
Adapted from slides by Marty Stepp and Stuart Reges
CSc 110, Autumn 2016 Lecture 14: Boolean Logic
Adapted from slides by Marty Stepp and Stuart Reges
Adapted from slides by Marty Stepp and Stuart Reges
Adapted from slides by Marty Stepp and Stuart Reges
CSc 110, Spring 2018 Lecture 33: Dictionaries
Adapted from slides by Marty Stepp and Stuart Reges
CSc 110, Autumn 2016 Lecture 31: Encapsulation
CSc 110, Spring 2018 Lecture 9: Parameters, Graphics and Random
Homework 8: Critters (cont.)
CSc 110, Spring 2018 Lecture 17: while Loops and decomposition
CSc 110, Autumn 2016 Lecture 19: lists as Parameters
Lecture 23: Tuples Adapted from slides by Marty Stepp and Stuart Reges
CSc 110, Autumn 2016 Lecture 9: input; if/else
Lecture 22: lists Adapted from slides by Marty Stepp and Stuart Reges
CSc 110, Autumn 2017 Lecture 9: Graphics and Nested Loops
CSc 110, Autumn 2017 Lecture 27: Lists that change size and Tuples
CSc 110, Autumn 2016 Lecture 5: Loop Figures and Constants
CSc 110, Spring 2017 Lecture 39: searching and sorting
CSc 110, Autumn 2016 Lecture 20: Lists for Tallying; Text Processing
Adapted from slides by Marty Stepp and Stuart Reges
Adapted from slides by Marty Stepp and Stuart Reges
Adapted from slides by Marty Stepp and Stuart Reges
Adapted from slides by Marty Stepp and Stuart Reges
Lecture 23: Tuples Adapted from slides by Marty Stepp and Stuart Reges
Adapted from slides by Marty Stepp and Stuart Reges
Adapted from slides by Marty Stepp and Stuart Reges
CSc 110, Autumn 2016 Lecture 17: Line-Based File Input
CSc 110, Spring 2017 Lecture 20: Lists for Tallying; Text Processing
CSc 110, Spring 2018 Lecture 27: Lists that change size and File Output Adapted from slides by Marty Stepp and Stuart Reges.
CSc 110, Spring 2018 Lecture 8: input and Parameters
CSc 110, Spring 2018 Lecture 10: More Graphics
Adapted from slides by Marty Stepp and Stuart Reges
Adapted from slides by Marty Stepp and Stuart Reges
Adapted from slides by Marty Stepp and Stuart Reges
CSc 110, Autumn 2017 Lecture 8: More Graphics
CSc 110, Autumn 2016 Lecture 20: Lists for Tallying; Text Processing
Adapted from slides by Marty Stepp and Stuart Reges
Presentation transcript:

Adapted from slides by Marty Stepp and Stuart Reges CSc 110, Autumn 2017 Lecture 32: 2D Structures Adapted from slides by Marty Stepp and Stuart Reges

Exercise Consider the following function: def mystery(all, letters): for i in range(all): if all[i] in letters.values(): if all[i] not in letters.keys(): letters[all[i]] = i else: letters[all[i]] += i return result What is in the dictionary after calls with the following parameters? all: [b, l, u, e] letters: {s:b, p:t, o:u, t:t} dictionary:__________________________________________________________ all: [k, e, e, p] letters: {s:y, a:k, f:e, e:f} all: [s, o, b, e, r] letters: {b:b, o:o, o:o, k:k, s:s}

What is the right structure? You want to store a bunch of colors so you can later choose one at random. Batting order of a baseball team. Students names and their grades on a project. Friends names and their phone numbers Height, width and location of a sports field. Movies a person has watched. Items in a shopping cart. A student's grades.

What is the right structure? The grades for all students in a class All books in a store arranged by category Many recipes each containing many steps Phone numbers that have been called this month on a phone plan divided by area and country code for billing simplicity

Exercise We would like to store data for the class so that we can: Access the entire class list easily Access a section list easily What structure is appropriate for this problem? Sometimes it can be helpful to store a structure inside another structure