Download presentation
Presentation is loading. Please wait.
1
Introduction to Computational Thinking
Abstraction & Data Structures …more complex data structures (C) Dennis Kafura 2016
2
Combining lists and dictionaries
Lists and dictionaries are two forms of data structures – different schemes to organize and access data Representing the abstractions of complex real-world artifacts often requires some combination of these data structures Combining simple structures to form more complex ones (C) Dennis Kafura 2016
3
List of dictionaries A weather report abstraction has three properties
temperature humidity wind A weather forecast is a collection of instance of weather reports (C) Dennis Kafura 2016
4
A collection of dictionaries
Each instance of a weather report in the weather forecast can be represented separately Each instance of a weather report can be represented as a dictionary { “temperature”: 30, “humidity”: 20, “wind”: 3 } (C) Dennis Kafura 2016
5
A list of dictionaries The individual weather report instances (dictionaries) can be collectively represented in a list { ‘temperature’: 18, ‘humidity’: 90, ‘wind’: 15 } { ‘temperature’: 29, ‘humidity’: 100, ‘wind’: 5 } { ‘temperature’: 24, ‘humidity’: 30, ‘wind’: 19 } { ‘temperature’: 25, ‘humidity’: 50, ‘wind’: 10 } { ‘temperature’: 30, ‘humidity’: 20, ‘wind’: 3 } (C) Dennis Kafura 2016
6
List/dictionary in Python
{ ‘temperature’: 18, ‘humidity’: 90, ‘wind’: 15 } { ‘temperature’: 29, ‘humidity’: 100, ‘wind’: 5 } { ‘temperature’: 24, ‘humidity’: 30, ‘wind’: 19 } { ‘temperature’: 25, ‘humidity’: 50, ‘wind’: 10 } { ‘temperature’: 30, ‘humidity’: 20, ‘wind’: 3 } [ {‘temperature’ : 30, ‘humidity’ : 20, ‘wind’ : 3} , {‘temperature’ : 25, ‘humidity’ : 50, ‘wind’ : 10} , {‘temperature’ : 29, ‘humidity’ :100, ‘wind’ : 5} , {‘temperature’ : 18, ‘humidity’ : 90, ‘wind’ : 15} , {‘temperature’ : 24, ‘humidity’ : 30, ‘wind’ : 19} ], (C) Dennis Kafura 2016
7
Next steps Remember: Now With a list iterate through each element
for <item> in <list>: With a dictionary use a key to access a value value = dictionary[“key”] Now Do the first two problems Report/discuss (C) Dennis Kafura 2016
8
A dictionary with list values
An abstraction of a temperature forecast for multiple cities City Forecast “Blacksburg, VA” [76, 54, 72, 52, 64, 43, 66, 48, 71, 54] “Seattle, WA” [63, 56, 69, 55, 69, 54, 67, 52, 63, 51] “Miami, FL” [86, 69, 87, 71, 88, 64, 88, 72, 87, 73] “San Jose, CA” [79, 57, 82, 57, 83, 58, 84, 60, 80, 84] “New York, NY” [5, 8, 8, 3, 2, 1, 9, 5, -4, -10] (C) Dennis Kafura 2016
9
“Nested” iteration Nested: one (inner) iteration in the body of another (outer) iteration City Forecast “Blacksburg, VA” [ ] “Seattle, WA” “Miami, FL” “San Jose, CA” “New York, NY” for ….. : # each city # each temperature (C) Dennis Kafura 2016
10
Another graphic form [ list ] { City , Forecast } [ list ] City
“Blacksburg, VA” [76, 54, 72, 52, 64, 43, 66, 48, 71, 54] “Seattle, WA” [63, 56, 69, 55, 69, 54, 67, 52, 63, 51] “Miami, FL” [86, 69, 87, 71, 88, 64, 88, 72, 87, 73] “San Jose, CA” [79, 57, 82, 57, 83, 58, 84, 60, 80, 84] “New York, NY” [5, 8, 8, 3, 2, 1, 9, 5, -4, -10] { City , Forecast } string [ list ] int(eger) (C) Dennis Kafura 2016
11
Classwork Do problem 3 Report/discussion (C) Dennis Kafura 2016
12
Layers of Abstraction Many properties are often needed make our abstractions of the real world accurate Humans are not “wired” to handle many properties at one time (our short term memory allows about 7 +/- 1 things) We have devised ways of coping with this complexity through layers or hierarchy An entity is represented by few parts Each part is represented by a few sub-parts Each sub-part is …. (C) Dennis Kafura 2016
13
Layers of Abstraction Place Report Date . . . Temperature Humidity
Wind 76 55 18 City State Zip Blacksburg VA 24061 Month Day Year Time May 20 2015 Hour Min Sec 11 32 52 (C) Dennis Kafura 2016
14
Accessing a value forecast = To find the Zip code:
where = forecast[“Place’] code = where[“Zip”] or just code = forecast[“Place”][“Zip”] To find the Hour: when = forecast[“Date”][“Time”][“Hour”] (C) Dennis Kafura 2016
15
Demonstration Mapping the earthquakes data stream
Using Spyder’s variable explorer (C) Dennis Kafura 2016
16
Mapping diagram (C) Dennis Kafura 2016
17
To do Work on class assignments Self-assess
Are you solid on the concepts? If not, see me Are you up to date on homework? If not, catch up Have you identified your project data stream and questions? If not, see me and work on this (C) Dennis Kafura 2016
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.