Lists of Dictionaries Combining Data Storage Types.

Slides:



Advertisements
Similar presentations
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Advertisements

CATHERINE AND ANNIE Python: Part 3. Intro to Loops Do you remember in Alice when you could use a loop to make a character perform an action multiple times?
Introduction to arrays
One Dimensional Arrays
An Array A sequence of elements of a particular type Each element in the array has an index which gives its position in the sequence An array is declared.
DICTIONARIES. The Compound Sequence Data Types All of the compound data types we have studies in detail so far – strings – lists – Tuples They are sequence.
Dictionaries Last half of Chapter 5. Dictionary A sequence of key-value pairs – Key is usually a string or integer – Value can be any python object There.
UNESCO ICTLIP Module 4. Lesson 3 Database Design, and Information Storage and Retrieval Lesson 3. Information storage and retrieval using WinISIS.
DT211/3 Internet Application Development JSP: Processing User input.
Main Index Contents 11 Main Index Contents Abstract Model of a List Obj. Abstract Model of a List Obj. Insertion into a List Insertion into a List Linked.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Console Input Using the Scanner Class Starting with version 5.0, Java includes a class for doing.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 6: Lists, Tuples, and Dictionaries – Exercises Xiang Lian The University of Texas – Pan American Edinburg,
JaySummet IPRE Python Review 2. 2 Outline Compound Data Types: Strings, Tuples, Lists & Dictionaries Immutable types: Strings Tuples Accessing.
CSE 143 Lecture 7 Sets and Maps reading: ; 13.2 slides created by Marty Stepp
Tutorial 10 Dictionaries and Classes. Reminder Assignment 09 is due April 6 at 11:55pm (last day of classes) Next tutorial is on April 6 (Monday)
IE 212: Computational Methods for Industrial Engineering
CS 177 Week 11 Recitation Slides 1 1 Dictionaries, Tuples.
Lists in Python.
Computer Science 101 Lists in Python. The need for lists Often we need many different variables that play a similar role in the program Often we need.
Data Structures in Python By: Christopher Todd. Lists in Python A list is a group of comma-separated values between square brackets. A list is a group.
Handling Lists F. Duveau 16/12/11 Chapter 9.2. Objectives of the session: Tools: Everything will be done with the Python interpreter in the Terminal Learning.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Chapter 14 Tuples, Sets, and Dictionaries 1.
CSC Intro. to Computing Lecture 13: PALGO. Announcements Midterm is in one week  Time to start reviewing  We will do more review in class Tuesday.
Python Lists and Such CS 4320, SPRING List Functions len(s) is the length of list s s + t is the concatenation of lists s and t s.append(x) adds.
Copyrighted material John Tullis 10/17/2015 page 1 04/15/00 XML Part 3 John Tullis DePaul Instructor
Beyond Lists: Other Data Structures CS303E: Elements of Computers and Programming.
CompSci Today’s topics Java Review Just a bunch of headings meant to trigger questions A contraction of previous notes Upcoming Midterm Exam Reading.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
Array - adding to array at run time Please see speaker notes for additional information!
Web Tutorial Using the Assessor’s Site May 27, 1999.
Quick Start Guide: Filters Learn about: 1.What filters Are & Their Functionality 2.How to Create A Filter.
Dictionaries.   Review on for loops – nested for loops  Dictionaries (p.79 Learning Python)  Sys Module for system arguments  Reverse complementing.
Computer Programming TCP1224 Chapter 11 Arrays. Objectives Using Arrays Declare and initialize a one-dimensional array Manipulate a one-dimensional array.
PH24010 Data Handling and Statistics Use of MathCAD to handle statistical data Data storage in vectors and matrices MathCAD’s built-in functions: –Mean,
Structuring Data: Arrays ANSI-C. Representing multiple homogenous data Problem: Input: Desired output:
CS320n – Elements of Visual Programming Assignment Help Session.
CS190/295 Programming in Python for Life Sciences: Lecture 6 Instructor: Xiaohui Xie University of California, Irvine.
Python Programing: An Introduction to Computer Science
CS162 - Topic #12 Lecture: –Arrays with Structured Elements defining and using arrays of arrays remember pointer arithmetic Programming Project –Any questions?
CHAPTER 6 ARRAYS IN C 1 st semester King Saud University College of Applied studies and Community Service Csc 1101 F. Alakeel.
Python Arithmetic Operators OperatorOperationDescription +AdditionAdd values on either side of the operator -SubtractionSubtract right hand operand from.
Keywords: Range Trace table Testing List Index Activities: To create a trace table for a small piece of code using a set of data. Create a trace table.
Lists/Dictionaries. What we are covering Data structure basics Lists Dictionaries Json.
DAY 3. ADVANCED PYTHON PRACTICE SANGREA SHIM TAEYOUNG LEE.
Section06: Sequences Chapter 4 and 5. General Description "Normal" variables x = 19 – The name "x" is associated with a single value Sequence variables:
Intro to CS Nov 17, 2016.
Now with a speaking professor! (hopefully...)
When to use Tuples instead of Lists
Department of Computer Science,
Relations and Functions
Visual Basic .NET BASICS
COSC 1323 – Computer Science Concepts I
Lists in Python.
Creation, Traversal, Insertion and Removal
Flooding © 2018.
CS190/295 Programming in Python for Life Sciences: Lecture 6
Data Structures – 1D Lists
Coding Concepts (Data Structures)
Introduction to Dictionaries
Python 19 Mr. Husch.
Programming Control Structures with JavaScript Part 2
Loops and Arrays in JavaScript
Python Basics with Jupyter Notebook
Python Review
Python 19 Mr. Husch.
For loop Using lists.
What you need to do… Drag the pieces of code into the correct order like you can see in the EXAMPLE below. print ( “ int input ) = + Hello world chr ord.
Week 1.
Chapter 2 Functions, Equations, and Graphs
Dictionary.
Presentation transcript:

Lists of Dictionaries Combining Data Storage Types

123 King St. 12 Woodbine 18 Fairfield 345 Johnson addresses } element { list index (subscript) Review of Lists A Simple Diagram of a List

For example, given our list on the left, the following Python command: addresses [3] = "345 Johnson“ – the name of the list is addresses – the element is addresses [3] -> pronounced “addresses sub 3” – the subscript or index is 3 – the data assigned to this element is 345 Johnson 123 King St. 12 Woodbine 18 Fairfield 345 Johnson addresses

Review of Dictionaries Remember that dictionaries are defined as a series of key:data pairs. This means that individual pieces of data are accessed using a key instead of their relative position in the dictionary. NumberStreetCity 18Fairfield BoulevardAmherstview address The name of the dictionary is address and it contains three keys:data pairs:  Number -> 18  Street -> Fairfield Boulevard  City -> Amherstview A Simple Diagram of a Dictionary

Lists of Dictionaries manyAddresses NumberStreetCity 1233King StreetKingston NumberStreetCity 18Fairfield BoulevardAmherstview Number Street City 423-A Carter Crescent Bath NumberStreetCity 77Dawson RoadKingston A list contains a number elements identified with a subscript (index) which contain data. Instead of one piece of data, each element in a list can contain a dictionary containing multiple key:value pairs.

For example, given our list on the previous slide, the following Python command: addresses [2] [“Street”] = “Carter Crescent“ – the name of the list is addresses – the element is addresses [2] -> pronounced “addresses sub 2” – the subscript or index is 2 – the data assigned to the addresses [2] a dictionary with three keys. – the key (field) of the dictionary in the element is “Street” – the data assigned to the key Street in the element addresses [2] is Carter Crescent

manyAddresses = [ ] # Creates an empty list for i in range (0, 4): singleAddress = {} # Creates an empty dictionary # Must be in the loop # Allows the user to input data into the dictionary singleAddress ["Name"] = input ("Enter street number") singleAddress ["Street"] = input ("Enter street name") singleAddress ["City"] = input ("Enter the city") # Adds the dictionary to the list manyAddresses.append (singleAddress) Program to Create a Lists of Dictionaries

manyAddresses NumberStreetCity 18Fairfield BoulevardAmherstview NumberStreetCity 1233King StreetKingston NumberStreetCity singleAddress How the Program Works