Nate Brunelle Today: Dictionaries

Slides:



Advertisements
Similar presentations
I210 review Fall 2011, IUB. Python is High-level programming –High-level versus machine language Interpreted Language –Interpreted versus compiled 2.
Advertisements

Binary Search Visualization i j.
1 Introduction to Arrays Problem: –Input 5 scores, compute total, average –Input Example –test scores,employees,temperatures.
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.
Chapter 10 Strings, Searches, Sorts, and Modifications Midterm Review By Ben Razon AP Computer Science Period 3.
Beyond Lists: Other Data Structures CS303E: Elements of Computers and Programming.
 2006 Pearson Education, Inc. All rights reserved Searching and Sorting.
SEARCHING. Vocabulary List A collection of heterogeneous data (values can be different types) Dynamic in size Array A collection of homogenous data (values.
Built-in Data Structures in Python An Introduction.
Chapter 8 More On Functions. "The Practice of Computing Using Python", Punch & Enbody, Copyright © 2013 Pearson Education, Inc. First cut, scope.
Python Functions.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 9 Dictionaries and Sets.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 8: Fun with strings.
CS105 STRING LIST TUPLE DICTIONARY. Characteristics of Sequence What is sequence data type? It stores several objects Each object has an order Each object.
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.
CompSci 100E 18.1 Testing and Debugging Robert A Wagner.
CIT 590 Intro to Programming Lecture 4. How are assignments evaluated Pay attention to what the HW says it is trying to teach you about ‘modular programming’
 1 Searching. Why searching? Searching is everywhere. Searching is an essential operation for a dictionary and other data structures. Understand the.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 17: Linked Lists.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 18: Linked Lists.
 Introduction to Search Algorithms  Linear Search  Binary Search 9-2.
More Python Data Structures  Classes ◦ Should have learned in Simpson’s OOP ◦ If not, read chapters in Downey’s Think Python: Think like a Computer Scientist.
Intro to CS Nov 21, 2016.
16 Searching and Sorting.
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
Chapter 5 - Control Structures: Part 2
Data types: Complex types (Dictionaries)
Ruth Anderson UW CSE 160 Spring 2018
Nate Brunelle Today: Pseudo-Code, Party
Introduction to Strings
Introduction to Strings
Intro to Computer Science CS 1510 Dr. Sarah Diesburg
COSC 1323 – Computer Science Concepts I
Ruth Anderson UW CSE 160 Winter 2017
Intro to Computer Science CS 1510 Dr. Sarah Diesburg
Sharing, mutability, and immutability
Nate Brunelle Today: Repetition, Repetition
Nate Brunelle Today: Slicing, Debugging, Style
MSIS 655 Advanced Business Applications Programming
CSE 373: Data Structures and Algorithms
CSE 373 Data Structures and Algorithms
CSE 373: Data Structures and Algorithms
Sharing, mutability, and immutability
Introduction to Dictionaries
24 Searching and Sorting.
Nate Brunelle Today: Turtles
CS 1111 Introduction to Programming Fall 2018
Nate Brunelle Today: Lists
Introduction to Strings
Nate Brunelle Today: Dictionaries
6. Dictionaries and sets Rocky K. C. Chang 18 October 2018
(more) Python.
CS1110 Today: collections.
Dictionaries: Keeping track of pairs
Nate Brunelle Today: Values and Types
CISC101 Reminders Assignment 2 due today.
Introduction to Strings
Python Review
CSE 231 Lab 8.
Nate Brunelle Today: Style, Collections
Nate Brunelle Today: Strings, Type Casting
Introduction to Strings
Nate Brunelle Today: Pseudo-Code
Python fundamental.
Tuple.
Presentation transcript:

Nate Brunelle Today: Dictionaries CS1110 Nate Brunelle Today: Dictionaries

Questions?

Tips for fixing bugs in code Know what your code should do Read error messages Believe the error message Print every variable Binary search Test more Look for “code coverage”

Binary search Start: a line you know is before the bug End: a line you know is after the bug Middle: the line halfway between start and end Check whether Middle has the bug. If so, then Middle is the new End. Otherwise if Middle has no bug, then Middle is the new Start. You just ruled out half of the remaining lines of code as the bad ones! Keep going until you have only 1 line of code left. That one has the bug.

Test Cases Try winning: fun, f, u, n Capital: FUN, f, u ,n 1234, 1 Fun, fn, Fun, x, x, x, x, x, x F_n, n, _

Collections Order doesn’t matter, No Repetition Order Matters, Repetition ok Examples: String List Tuple Range Counting starts at 0 collection[index] gives a specific value in the collection Order doesn’t matter, No Repetition Examples: Set Dict Map Table

Set Things are unordered Cannot have repetition

Dict A set of key:value mappings d = { } d[‘name’] = 1 d[‘name’]

Dict Somewhat like variables, somewhat like a list

Dict is like variables Gives names to values Create using = Reassign using = Easy to go from name to a value Very hard to go from value to name

Dict is like a list Index to access members Index must be an int Key to access members Key can be any immutable type No rules for values of keys To add in a new thing: d[key] = … Index to access members Index must be an int Indexes cannot be skipped To add in a new thing: lst.append(…)