Python: Dictionaries Nicola Licata Charis Kao Dan Green.

Slides:



Advertisements
Similar presentations
» PHP arrays are lists of values stored in key-value pairs. » Uses of arrays: Many built-in PHP environment variables. Database functions use arrays.
Advertisements

How data is stored. Data can be stored in paper-based systems including: Reference books Dictionaries Encyclopaedias Directories Index Files Filing systems.
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?
Indexing. Efficient Retrieval Documents x terms matrix t 1 t 2... t j... t m nf d 1 w 11 w w 1j... w 1m 1/|d 1 | d 2 w 21 w w 2j... w 2m 1/|d.
Ruby on Rails Model of MVC. Model-View-Controller Paradigm A way of organizing a software system Benefits: Isolation of business logic from the user interface.
Guide to Programming with Python
Fundamentals of Python: From First Programs Through Data Structures
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.
Python, CGI November 23, Unit 8. So Far We can write programs in Python (in theory at least) –Conditionals –Variables –While loops We can create a form.
Introducing Hashing Chapter 21 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Madlib-Input, Strings, and Lists in Scratch Barb Ericson Georgia Tech June 2011.
Access 2007 ® Use Databases How can Microsoft Access 2007 help you to enter and organize information?
Create Forms Lesson 5. Software Orientation Creating Forms A form is a database object –enter, edit, or display data from a table or query Providing.
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.
Collecting Things Together - Lists 1. We’ve seen that Python can store things in memory and retrieve, using names. Sometime we want to store a bunch of.
Built-in Data Structures in Python An Introduction.
What have we learned?. What is a database? An organized collection of related data.
Representing Characters in a computer Pressing a key on the computer a code is generated that the computer can convert into a symbol for displaying or.
5 1 Data Files CGI/Perl Programming By Diane Zak.
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
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.
Guide to Programming with Python Chapter Five Lists and dictionaries (data structure); The Hangman Game.
CSC Introduction to Data Structures Devon M. Simmonds Computer Science Department University of North Carolina Wilmington Wilmington, NC 28403
7. Lists 1 Let’s Learn Saenthong School, January – February 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
CSCI 6962: Server-side Design and Programming Shopping Carts and Databases.
Managing references Mehdi Osooli M.S.C in Epidemiology Department of Epidemiology & Biostatistics School of Public Health Tehran University of Medical.
Unit-8 Introduction Of MySql. Types of table in PHP MySQL supports various of table types or storage engines to allow you to optimize your database. The.
Magic 8 ball. "Design and write a python program that emulates a Magic Eight Ball. Your program should continually prompt the user to enter a question.
Notes: **A Row is considered one Record. **A Column is a Field. A Database is…  an organized set of stored information usually on one topic  a collection.
Database (Microsoft Access). Database A database is an organized collection of related data about a specific topic or purpose. Examples of databases include:
CS2910 Week 6, Lab Today Dictionaries in Python SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1.
Today… Files from the Web! Dictionaries. Lists of lists. Winter 2016CISC101 - Prof. McLeod1.
Dictionaries Alexandra Stefan CSE1310 – University of Texas at Arlington.
Copyright © 2013 by John Wiley & Sons. All rights reserved. SETS AND DICTIONARIES CHAPTER Slides by James Tam Department of Computer Science, University.
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
 At the end of the class students should:  distinguish between data and information.  explain the characteristics and forms of Information Processing.
RECORDS MANAGEMENT Judith Read and Mary Lea Ginn Chapter 10 Geographic Records Management 1 © 2016 Cengage Learning ®. May not be scanned, copied or duplicated,
Final words on Lists.
Intro to CS Nov 17, 2016.
Lesson 10: Dictionaries Topic: Introduction to Programming, Zybook Ch 9, P4E Ch 9. Slides on website.
Databases.
Python – May 18 Quiz Relatives of the list: Tuple Dictionary Set
KeePass Password Safe Dan Koller Jesse Cowan.
CMSC201 Computer Science I for Majors Lecture 17 – Dictionaries
CMSC201 Computer Science I for Majors Lecture 21 – Dictionaries
When to use Tuples instead of Lists
Containers and Lists CIS 40 – Introduction to Programming in Python
More on Lists.
Department of Computer Science,
EMR field in Portals Work History page
LING 388: Computers and Language
Dictionaries GENOME 559: Introduction to Statistical and Computational Genomics Prof. William Stafford Noble.
Python I/O.
Databases Lesson 2.
Guide to Programming with Python
Data Structures – 1D Lists
Python dicts and sets Some material adapted from Upenn cis391 slides and other sources.
Remembering lists of values lists
IST256 : Applications Programming for Information Systems
Lesson 10: Dictionaries Class Chat: Attendance: Participation
Programming Control Structures with JavaScript Part 2
Final words on Lists.
CHAPTER 4: Lists, Tuples and Dictionaries
Introduction to Programming with Python
Introduction to Python
Winter 2019 CISC101 5/26/2019 CISC101 Reminders
Sample lecture slides.
Dictionary.
Presentation transcript:

Python: Dictionaries Nicola Licata Charis Kao Dan Green

What Are Dictionaries? Similar to lists Separates the scrubs from the pros Indexed by keys that the programmer sets instead of numbers

Syntax #examplecode.exe loading….. #important thing to note, use {} instead of [] charizard = {‘name’: ‘Charizard’, ‘type’: ‘fire’, ‘trainer’: ‘Ash’} league = {'name': 'Zed', 'scaling': ‘AD’} print(charizard[‘type’]) print(league[‘scaling’]) >>>fire >>>AD

Adding Parts to a Dictionary You can easily add parts to a list by using the following code charizard = {‘name’: ‘Charizard’, ‘type’: ‘fire’, ‘trainer’: ‘Ash’} charizard[‘weakness’] = ‘water’ print(charizard) >>>{‘name’: ‘Charizard’, ‘type’: ‘fire’, ‘trainer’: ‘Ash’, ‘weakness’: water}

Deleting Parts of Your List Use del to delete individual parts of your list charizard = {‘name’: ‘Charizard’, ‘type’: ‘fire’, ‘trainer’: ‘Ash’} del charizard[‘trainer’] print(charizard) >>>{‘name’: ‘Charizard’, ‘type’: ‘fire’}

Printing The Keys You can print just the keys of the list by using the following code charizard = {‘name’: ‘Charizard’, ‘type’: ‘fire’, ‘trainer’: ‘Ash’} print(list(charizard.keys())) >>>[‘name’, ‘type’, ‘trainer’]

Dictionaryception You can have dictionaries within dictionaries charizard = {‘name’: ‘Charizard’, ‘type’: ‘fire’, ‘trainer’: ‘Ash’} raichu = {‘name’: ‘Raichu’, ‘type’: ‘fire’, ‘trainer’: ‘Gary’} pokemon = {‘charizard’: charizard, ‘raichu’: raichu} print(pokemon) >>> {‘charizard’: {‘name’: ‘Charizard’, ‘type’: ‘fire’, ‘trainer’: ‘Ash’}, ‘raichu’: {‘name’: ‘Raichu’, ‘type’: ‘fire’, ‘trainer’: ‘Gary’}}

Recap Video

Programming Challenge Write a code that sorts all items alphabetically in a dictionary without using any form of the sort command.

Just kidding, we’re reasonable.

Warm-Up Challenge Write a program that has multiple sub-dictionaries within one “master dictionary” print the “master dictionary” and then print each separate part of the master dictionary on its own separate line *Pro-Tip*: use other things you have learned in this class

Answer dict1 = {‘example’ = 1} dict2 = {‘example’ = 2} masterdict = {‘dict1’: dict1, ‘dict2’: dict2} masterlist = [dict1, dict2] print(masterdict) for x in range(len(masterlistprint)): print(masterlistprint[x])

Test to Separate The Men From The Boys Create a database that stores people’s names and the towns they live in Allow the user to add/remove entries Also allow the user to show specific entries