Dictionaries Alexandra Stefan CSE1310 – University of Texas at Arlington.

Slides:



Advertisements
Similar presentations
Guide to Programming with Python
Advertisements

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.
Python Dictionary.
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.
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,
1 Essential Computing for Bioinformatics Bienvenido Vélez UPR Mayaguez Lecture 5 High-level Programming with Python Part II: Container Objects Reference:
Introduction to Python Guido van Rossum Director of PythonLabs at Zope Corporation
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.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Chapter 14 Tuples, Sets, and Dictionaries 1.
STL-Associative Containers. Associative Containers Sequence containers : "This is item 0, this is item 1, this is item 2…“ Associative containers : –
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.
Beyond Lists: Other Data Structures CS303E: Elements of Computers and Programming.
Built-in Data Structures in Python An Introduction.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 8 Working.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 8 Lists and Tuples.
9/23/2015BCHB Edwards Advanced Python Data Structures BCHB Lecture 7.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 9 Dictionaries and Sets.
Chapter 9 Dictionaries and Sets.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 8: Fun with strings.
Tuples and Dictionaries Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 6: Lists, Tuples, and Dictionaries Xiang Lian The University of Texas – Pan American Edinburg, TX
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.
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.
Guide to Programming with Python Chapter Five Lists and dictionaries (data structure); The Hangman Game.
LECTURE 3 Python Basics Part 2. FUNCTIONAL PROGRAMMING TOOLS Last time, we covered function concepts in depth. We also mentioned that Python allows for.
LISTS and TUPLES. Topics Sequences Introduction to Lists List Slicing Finding Items in Lists with the in Operator List Methods and Useful Built-in Functions.
7. Lists 1 Let’s Learn Saenthong School, January – February 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
Dictionaries Intro to Computer Science CS 1510 Dr. Sarah Diesburg.
Introduction to Python Aug 22, 2013 Hee-gook Jun.
Python Data Structures By Greg Felber. Lists An ordered group of items Does not need to be the same type – Could put numbers, strings or donkeys in the.
Strings CSE 1310 – Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington 1.
Introduction to Programming Oliver Hawkins. BACKGROUND TO PROGRAMMING LANGUAGES Introduction to Programming.
Dictionaries. The compound types you have learned about - - strings, lists, and tuples – use integers as indices. If you try to use any other type as.
Python Sets and Dictionaries Peter Wad Sackett. 2DTU Systems Biology, Technical University of Denmark Set properties What is a set? A set is a mutable.
Dictionaries Ruth Anderson UW CSE 160 Winter
Lists/Dictionaries. What we are covering Data structure basics Lists Dictionaries Json.
Scientific Programming in Python -- Cheat Sheet
Topics Dictionaries Sets Serializing Objects. Topics Dictionaries Sets Serializing Objects.
When to use Tuples instead of Lists
Ruth Anderson CSE 140 University of Washington
Intro to Computer Science CS 1510 Dr. Sarah Diesburg
Intro to Computer Science CS 1510 Dr. Sarah Diesburg
Bryan Burlingame Halloween 2018
CHAPTER THREE Sequences.
Guide to Programming with Python
Ruth Anderson UW CSE 160 Winter 2017
Topics Sequences Introduction to Lists List Slicing
Topics Dictionaries Sets Serializing Objects. Topics Dictionaries Sets Serializing Objects.
Dictionaries Dictionary: object that stores a collection of data
Michael Ernst CSE 140 University of Washington
6. Dictionaries and sets Rocky K. C. Chang 18 October 2018
By- Anshul Kumar Class: XI “B”
CISC101 Reminders Assignment 2 due today.
CHAPTER 4: Lists, Tuples and Dictionaries
Ruth Anderson CSE 160 University of Washington
15-110: Principles of Computing
Bryan Burlingame Halloween 2018
Topics Sequences Introduction to Lists List Slicing
Ruth Anderson UW CSE 160 Spring 2018
CSE 231 Lab 8.
Introduction to Dictionaries
Dictionary.
Python List.
Tuple.
Ruth Anderson UW CSE 160 Winter 2016
Presentation transcript:

Dictionaries Alexandra Stefan CSE1310 – University of Texas at Arlington

Dictionary A sequence of key-value pairs: {key:value, key:value,… key: value} Optimized for efficient search based on the key May not always print the elements in the same order – As you make modifications (insert/delete elements) the order of the pairs may change to enable fast searching

Legal Keys No duplicate keys – Cannot have multiple entries for a key Keys must be immutable types – Strings – Integers – Tuples Mix and match is okay Slide by Chris Conly

Working with dictionaries {key:value, key:value,… key: value} What operations would you like? What operations do you know from the other collections?

Working with dictionaries They are mutable Shallow copies d = {key:value, key:value,… key: value } Functions: – d[new_key] = new_value – del d[key] – d.items(), d.keys(), d.values() list(d.keys()), sorted(d.keys()) – len(d) : number of key-value pairs – in : verifies that a key is in the dictionary – min(__), max(__)

keys(), values(), items() They are called view objects They reflect changes made to the dictionary – If you add or delete items in the dictionary, the views will reflect that “If keys, values and items views are iterated over with no intervening modifications to the dictionary, the order of items will directly correspond.” – Python Standard Library To get a list of them use the list constructor: – list(d.keys()), list(d.values()), list(d.items()) – How connected are the lists and the views they are based on? d = {1:[1,2]}, lv = list(d.values()), d[1][0] = 10, d, lv, lv[0][1] = 200, lv, d