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.

Slides:



Advertisements
Similar presentations
CHAPTER 4 AND 5 Section06: Sequences. General Description "Normal" variables x = 19  The name "x" is associated with a single value Sequence variables:
Advertisements

Chapter 6 Lists and Dictionaries CSC1310 Fall 2009.
Python Mini-Course University of Oklahoma Department of Psychology Lesson 16 Dictionaries 5/10/09 Python Mini-Course: Lesson 16 1.
9 Dictionaries © 2010 David A Watt, University of Glasgow Accelerated Programming 2 Part I: Python Programming 1.
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.
Sequences The range function returns a sequence
Sequences A sequence is a list of elements Lists and tuples
1 Sequences A sequence is a list of elements Lists and tuples – Lists mutable – Tuples immutable Sequence elements can be indexed with subscripts – First.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 6: Lists, Tuples, and Dictionaries – Exercises Xiang Lian The University of Texas – Pan American Edinburg,
COMPSCI 105 S Principles of Computer Science Recursion 3.
JaySummet IPRE Python Review 2. 2 Outline Compound Data Types: Strings, Tuples, Lists & Dictionaries Immutable types: Strings Tuples Accessing.
Lecture 23 – Python dictionaries 1 COMPSCI 101 Principles of Programming.
Writing Solid Code Introduction to Python. Program 1 python -c "print 'Hello World' “ python -c "import time; print time.asctime()“ Start an interactive.
 1 String and Data Processing. Sequential Processing Processing each element in a sequence for e in [1,2,3,4]: print e for c in “hello”: print c for.
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)
Python Data Structures
Python Programming Chapter 10: Dictionaries Saad Bani Mohammad Department of Computer Science Al al-Bayt University 1 st 2011/2012.
CS 177 Week 11 Recitation Slides 1 1 Dictionaries, Tuples.
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.
Sorting and Modules. Sorting Lists have a sort method >>> L1 = ["this", "is", "a", "list", "of", "words"] >>> print L1 ['this', 'is', 'a', 'list', 'of',
Python Mini-Course University of Oklahoma Department of Psychology Day 2 – Lesson 9 Iteration: Recursion 5/02/09 Python Mini-Course: Day 3 - Lesson 9 1.
CS212: DATA STRUCTURES Lecture 10:Hashing 1. Outline 2  Map Abstract Data type  Map Abstract Data type methods  What is hash  Hash tables  Bucket.
Data Collections: Dictionaries CSC 161: The Art of Programming Prof. Henry Kautz 11/4/2009.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Chapter 14 Tuples, Sets, and Dictionaries 1.
LECTURE 37: ORDERED DICTIONARY CSC 212 – Data Structures.
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.
Recap form last time How to do for loops map, filter, reduce Next up: dictionaries.
Data Collections: Lists CSC 161: The Art of Programming Prof. Henry Kautz 11/2/2009.
9/23/2015BCHB Edwards Advanced Python Data Structures BCHB Lecture 7.
Dictionaries.   Review on for loops – nested for loops  Dictionaries (p.79 Learning Python)  Sys Module for system arguments  Reverse complementing.
Author: Takdir, S.ST. © Sekolah Tinggi Ilmu Statistik.
Computer Science 112 Fundamentals of Programming II Implementation Strategies for Unordered Collections.
Tuples and Dictionaries Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
14. DICTIONARIES AND SETS Rocky K. C. Chang 17 November 2014 (Based on from Charles Dierbach, Introduction to Computer Science Using Python and Punch and.
Lists of Dictionaries Combining Data Storage Types.
Compsci 101.2, Fall Plan for October 29 l Review dictionaries and their use  Very efficient, easy to use  Efficiency doesn't matter much for.
Introduction to Computing Using Python Dictionaries: Keeping track of pairs  Class dict  Class tuple.
CSE 130 : Winter 2009 Programming Languages Lecture 11: What’s in a Name ?
Tutorial 10 Dictionaries and Classes. Reminder Assignment 09 is due FRIDAY, Dec 4 at 4:00 pm.
CS190/295 Programming in Python for Life Sciences: Lecture 6 Instructor: Xiaohui Xie University of California, Irvine.
Compsci 101.2, Fall Plan for October l Structuring Data and Code for Efficiency  Computer time, how expensive is it?  Data storage, how.
Dictionaries Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Dictionaries Intro to Computer Science CS 1510 Dr. Sarah Diesburg.
Introduction to Python Aug 22, 2013 Hee-gook Jun.
Dictionaries and File I/O George Mason University.
Introduction to Programming Oliver Hawkins. BACKGROUND TO PROGRAMMING LANGUAGES Introduction to Programming.
Embedded Software Design Week V Python Lists and Dictionaries PWM LED 1-Wire Temperature Sensor.
1 Python Data Structures LING 5200 Computational Corpus Linguistics Martha Palmer.
Dictionaries Alexandra Stefan CSE1310 – University of Texas at Arlington.
Lists/Dictionaries. What we are covering Data structure basics Lists Dictionaries Json.
Guide to Programming with Python Chapter Four Strings, and Tuples; for Loops: The Word Jumble Game.
Section06: Sequences Chapter 4 and 5. General Description "Normal" variables x = 19 – The name "x" is associated with a single value Sequence variables:
Scientific Programming in Python -- Cheat Sheet
Section06: Sequences Chapter 4 and 5.
Algorithmic complexity: Speed of algorithms
CMSC201 Computer Science I for Majors Lecture 22 – Searching
Announcements Project 4 due Wed., Nov 7
Dictionaries, File operations
Intro to Computer Science CS 1510 Dr. Sarah Diesburg
COSC 1323 – Computer Science Concepts I
Lists in Python.
Intro to Computer Science CS 1510 Dr. Sarah Diesburg
Strings and Lists – the split method
Recitation Outline C++ STL associative containers Examples
CEV208 Computer Programming
Algorithmic complexity: Speed of algorithms
Algorithmic complexity: Speed of algorithms
Dictionary.
Introduction to Computer Science
Presentation transcript:

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 is no order to the elements – So, there isn't a first or a last element – Python uses its own algorithm to order elements (for efficient access) You access values by using the key.

Dictionary operations Creating an empty dictionary: D = {} Creating a dictionary with string-float pairs D2 = {"ABC":42.9, "DEF":13.8, "GHI":-19.1} Getting a list of keys or values D2.keys() # Returns ["ABC", "GHI", "DEF"] or something like this. Getting a list of values D2.values() # Returns [42.9, -19.1, 13.8]

Dictionary Index'ing Using an existing element print(D2["ABC"]) Changing a value for an existing key D2["ABC"] = Adding a new value D2["XYZ"] = 0.0 Note how this looks the same as modifying.

Dictionary examples [Using integers as a key] [Reiner Tile Sets…]