Lesson 10: Dictionaries Topic: Introduction to Programming, Zybook Ch 9, P4E Ch 9. Slides on website.

Slides:



Advertisements
Similar presentations
CIS101 Introduction to Computing Week 11 Spring 2004.
Advertisements

Summer  Session starts at 11:00 am ◦ We’ll be online shortly ◦ Speaker test starts about 10:45  To ask questions, ◦ use the chat window.
November 15, 2005ICP: Chapter 7: Files and Exceptions 1 Introduction to Computer Programming Chapter 7: Files and Exceptions Michael Scherger Department.
Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
COMP 171: Principles of Computer Science I John Barr.
AUTOMATION OF WEB-FORM CREATION - KINNERA ANGADI – MS FINAL DEFENSE GUIDANCE BY – DR. DANIEL ANDRESEN.
Functions, Procedures, and Abstraction Dr. José M. Reyes Álamo.
Intro Python: Variables, Indexing, Numbers, Strings.
TECHNICAL ORIENTATION WINTER Technical Orientation Session starts at 2:00 pm We’ll be online shortly Speaker test starts about 1:45 To ask questions,
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 9 Dictionaries and Sets.
OCR GCSE Computing © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 1: Introduction.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
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.
ECE 456 Computer Architecture Lecture #9 – Input/Output Instructor: Dr. Honggang Wang Fall 2013.
Google maps engine and language presentation Ibrahim Motala.
Quiz 3 Topics Functions – using and writing. Lists: –operators used with lists. –keywords used with lists. –BIF’s used with lists. –list methods. Loops.
Lesson 11: Web Services and API's
Lesson 06: Functions Class Participation: Class Chat:
Lesson 03: Variables and Types
Development Environment
Exam #1 You will have exactly 30 Mins to complete the exam.
Lesson 08: Files Class Participation: Class Chat: Attendance Code 
Lesson 07: Strings Class Chat: Attendance: Participation
Topics Dictionaries Sets Serializing Objects. Topics Dictionaries Sets Serializing Objects.
Lesson 04: Conditionals Topic: Introduction to Programming, Zybook Ch 3, P4E Ch 3. Slides on website.
Introduction Python is an interpreted, object-oriented and high-level programming language, which is different from a compiled one like C/C++/Java. Its.
IST256 : Applications Programming for Information Systems
Department of Computer Science,
Lesson 05: Iterations Class Chat: Attendance: Participation
Lesson 11: Web Services & API's
Lesson 07: Strings Topic: Introduction to Programming, Zybook Ch 6, P4E Ch 6. Slides on website.
Functions CIS 40 – Introduction to Programming in Python
IST256 : Applications Programming for Information Systems
Lesson 12: Data Analysis Topic: Data Analysis, Readings on website.
Week 1 Gates Introduction to Information Technology cosc 010 Week 1 Gates
Lesson 13: Visualizations
Introduction to Python
Lesson 04: Conditionals Class Chat: Attendance: Participation
Lesson 05: Iterations Topic: Introduction to Programming, Zybook Ch 4, P4E Ch 5. Slides on website.
Functions, Procedures, and Abstraction
CISC101 Reminders Slides have changed from those posted last night…
Lesson 08: Files Topic: Introduction to Programming, Zybook Ch 7, P4E Ch 7. Slides on website.
Learning Outcomes –Lesson 4
Lesson 09: Lists Topic: Introduction to Programming, Zybook Ch 8, P4E Ch 8. Slides on website.
LING 388: Computers and Language
I210 review.
Lesson 06: Functions Class Chat: Attendance: Participation
Lesson 09: Lists Class Chat: Attendance: Participation
Python Tutorial for C Programmer Boontee Kruatrachue Kritawan Siriboon
Lesson 03: Variables and Types
Topics Sequences Introduction to Lists List Slicing
IST256 : Applications Programming for Information Systems
Lesson 08: Files Class Chat: Attendance: Participation
Lesson 11: Web Services and API's
Topics Dictionaries Sets Serializing Objects. Topics Dictionaries Sets Serializing Objects.
CS 1111 Introduction to Programming Fall 2018
Lesson 10: Dictionaries Class Chat: Attendance: Participation
Topics Sequences Introduction to Lists List Slicing
5/8/2019 3:20 AM bQuery-Tool 3.0 A new and elegant way to create queries and ad-hoc reports on your Baan/Infor ERP LN data. This Baan session is a query.
Lesson 02: Introduction to Python
Winter 2019 CISC101 5/26/2019 CISC101 Reminders
L L Line CSE 420 Computer Games Lecture #3 Introduction to Python.
IST256 : Applications Programming for Information Systems
Lesson 07: Strings Class Chat: Attendance: Participation
CSE 231 Lab 15.
CS313T Advanced Programming language
IST256 : Applications Programming for Information Systems
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Lesson 10: Dictionaries Topic: Introduction to Programming, Zybook Ch 9, P4E Ch 9. Slides on website.

Exam #2 – Good Luck! The exam is closed book, closed computer and no phones or any other devices! You will have 30 mins to complete the exam. When time is up exam will auto submit. Do not leave the blackboard window! you will automatically receive a 0 no exceptions! The password is: Jyan73oP

Agenda Dictionaries as key-value pairs. Basic dictionary operations such as getting/setting keys and values Common dictionary use cases, such as representing complex objects. List of dictionary as an in-memory database of objects. Using the json library to load and save dictionaries to files. You’ve Read: Zybook Ch9 P4E Ch9

Connect Activity Question: A Python Dictionary is a Immutable Sequence Type Mutable Mapping Type Mutable Sequence Type Immutable Mapping Type

Dictionaries The dict type is designed to store key-value pairs. In Python this is known as a mapping type. font={‘Name’:’Arial’,’Size’: 8} Python dictionaries are mutable which means you can change the values. Dictionary values are accessed by key not by index. font[‘Name’] = “Courier”

Watch Me Code 1 Dictionary Basics: Create a dictionary Update its value Print it out Short and sweet demo

Dictionary Methods Like str and list, the dict type has its own set of built- in functions. https://docs.python.org/3/library/stdtypes.html#map ping-types-dict

Watch Me Code 2 Dictionary Methods: Handling KeyError using get() to avoid KeyError values() keys() delete a key Short and sweet demo

Check Yourself: Dictionaries What is the output on line 2? 2 '2' 6 KeyError

Dictionaries or Lists? When do you use a Python list versus a dict? Lists are for multiple versions of the same type. Ex: Student GPA's [3.4,2.8,4.0] Dictionaries are for single versions of different types. Ex: One Student's Name, GPA and Major { 'Name' : 'bob', 'GPA' : 3.4 }

Python's List of Dictionary For representing complex data structures… List students = [ { 'Name':'bob','GPA':3.4 }, { 'Name':'sue','GPA':2.8 }, { 'Name':'kent','GPA':4.0 } ] Dictionary

Watch Me Code 3 List of Dictionary: Using type() Method chaining to access values Short and sweet demo

Check Yourself: Matching Question s[0]['GPA'] s[3]['Name'] s[1]['name'] Answers 3.4 KeyError IndexError 'sue' Given the following Python code, match the Python Expression to it's answer

JSON and Python Dictionaries JSON (JavaScript Object Notation) is a standard, human- readable data format. It's a popular format for data on the web. JSON Can be easily converted to lists of dictionaries using Python's json module. Transferring JSON to Python is decoding. Transferring Python to JSON is encoding. This is easy to do in Python but challenging to do in most other languages.

Watch Me Code 4 Decode JSON Data Load into List of Dictionary Access data to obtain output Short and sweet demo

End-To-End Example European Country Locator Load JSON data for Countries in Europe Input a country Output Region (Southern Europe) Neighboring Countries

Advanced Topic. The following topic will not be on any exam or quiz, and it is not part of any homework assignments. There is an optional lesson in the Zybook about Object Oriented Programming. I am showing you this because I think its important. Those of you looking at more advanced projects will run into this when using other modules! If you don’t want to listen, feel free to start your ICCL.

Objects and Object Oriented Programming Everything in Python is and object. Objects are instances of classes, classes are object definitions, like function definitions. Objects can have properties, like variables but are for the object Objects can have their own functions. These are called methods. The first argument in a method is always self. Classes can inherit other classes. This allows for the new class to inherit properties and methods of the parent class.

Watch Me Code 5 Classes and Objects Defining methods on classes and using them for objects Class inheritence Short and sweet demo