CompSci 6 Introduction to Computer Science November 1, 2011 Prof. Rodger.

Slides:



Advertisements
Similar presentations
CompSci 101 Introduction to Computer Science February 3, 2015 Prof. Rodger Lecture given by Elizabeth Dowd.
Advertisements

CompSci 101 Introduction to Computer Science Feb 26, 2015 Prof. Rodger.
Lecture 12 – ADTs and Stacks.  Modularity  Divide the program into smaller parts  Advantages  Keeps the complexity managable  Isolates errors (parts.
Sequences A sequence is a list of elements Lists and tuples
Data Extraction From HTML Tables Cui Tao Department of Computer Science Brigham Young University.
 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.
CompSci 101 Introduction to Computer Science January 13, 2015 Prof. Rodger compsci 101 spring
CompSci 101 Introduction to Computer Science January 20, 2015 Prof. Rodger compsci 101, spring
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.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
CompSci Maps  Maps are another way of organizing data  Keys and Values  Each key maps to a value  Some keys can map to the same value  Can.
Today: Class Announcements Class Announcements Wednesday Warm-Up Wednesday Warm-Up 4.4 Notes 4.4 Notes Begin Homework Begin Homework Return Quizzes.
CompSci 6 Introduction to Computer Science October 20, 2011 Prof. Rodger.
CompSci 101 Introduction to Computer Science September 23, 2014 Prof. Rodger.
Built-in Data Structures in Python An Introduction.
CompSci 101 Introduction to Computer Science Sept. 9, 2014 Prof. Rodger President Brodhead speech graduation 2010 CompSci 101 Fall
111/18/2015CS150 Introduction to Computer Science 1 Announcements  I have not graded your exam yet.
Compsci 06/101, Fall What's ahead in Compsci 6/101? l Software architecture and design, why Jotto has modules and how communication works  We.
Author: Takdir, S.ST. © Sekolah Tinggi Ilmu Statistik.
CompSci 6 Introduction to Computer Science Sept 29, 2011 Prof. Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were not.
CompSci 6 Introduction to Computer Science November 8, 2011 Prof. Rodger.
CompSci 101 Introduction to Computer Science November 18, 2014 Prof. Rodger.
CompSci 101 Introduction to Computer Science March 3, 2015 Prof. Rodger compsci101 spring151.
Copyright © Ed2Net Learning, Inc. 1 Let’s do a few warm up exercises 1: Tanya has 23 straws, Ned has 19 straws, and Juan has 32 straws. Who has the most,
CompSci 6 Introduction to Computer Science September 13, 2011 Prof. Rodger.
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 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture Review for exam.
CompSci 101 Introduction to Computer Science February 10, 2015 Prof. Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were.
Creating Graphs. Where Does the Information Come From? A question is asked. A question is asked. What kind of ice cream does everyone like in our class?
Compsci 101.2, Fall Plan for October l Structuring Data and Code for Efficiency  Computer time, how expensive is it?  Data storage, how.
CompSci 101 Introduction to Computer Science Feb 24, 2015 Prof. Rodger.
CompSci 6 Introduction to Computer Science Sept. 20, 2011 Prof. Rodger CompSci 6 Fall
CompSci 101 Introduction to Computer Science February 11, 2016 Prof. Rodger.
CompSci 101 Introduction to Computer Science January 26, 2016 Prof. Rodger compsci 101, spring
CompSci 101 Introduction to Computer Science November 11, 2014 Prof. Rodger CompSci 101 Fall Review for exam.
CompSci 101 Introduction to Computer Science March 17, 2015 Prof. Rodger compsci 101, spring
CompSci 101 Introduction to Computer Science February 25, 2016 Prof. Rodger compsci101 spring20161.
CompSci 6 Introduction to Computer Science September 27, 2011 Prof. Rodger CompSci 6 Fall
CompSci 101 Introduction to Computer Science February 16, 2016 Prof. Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were.
CompSci 101 Introduction to Computer Science April 7, 2015 Prof. Rodger.
CompSci 101 Introduction to Computer Science March 24, 2016 Prof. Rodger compsci 101, spring
CompSci 101 Introduction to Computer Science March 8, 2016 Prof. Rodger.
CompSci 101 Introduction to Computer Science April 14, 2016 Prof. Rodger Lecture today by Sriram Vepuri.
CompSci 101 Introduction to Computer Science March 1, 2016 Prof. Rodger.
CompSci 101 Introduction to Computer Science April 14, 2016 Prof. Rodger compsci101 spring161.
CompSci 101 Introduction to Computer Science March 29, 2016 Prof. Rodger.
CompSci 101 Introduction to Computer Science February 5, 2015 Prof. Rodger Lecture given by Elizabeth Dowd compsci101 spring151.
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CSCI 104 Abstract Data Types
CompSci 6 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CMSC201 Computer Science I for Majors Lecture 17 – Dictionaries
Favorite Flavor Ice Cream Maker
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
COSC 1323 – Computer Science Concepts I
CompSci 101 Introduction to Computer Science
Introduction to Computer Science
مفاهیم بهره وري.
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Recitation Outline C++ STL associative containers Examples
6. Dictionaries and sets Rocky K. C. Chang 18 October 2018
CompSci 101 Introduction to Computer Science
Presentation transcript:

CompSci 6 Introduction to Computer Science November 1, 2011 Prof. Rodger

Announcements No Reading for next time, no RQ Apt-04 out, due Thursday Today –Writing Dictionaries/maps –Solving one apt sCourse

Dictionaries/Maps Dictionaries/maps are another way of organizing data Keys and Values –Each key maps to a value –Some keys can map to the same value –Can change the value a key maps to

Example Each student could be mapped to their favorite ice cream flavor

Implementing a Dictionary/Map Keys map to values Create Empty dictionary somemap = {} Put in a key and its value somemap[“Forbes”] = “Strawberry” Get a value for a dictionary value = somemap[“Forbes”] OR value = somemap.get(“Forbes”, “default”) Change a value for a dictionary somemap[“Forbes’] = “Chocolate”

More on using a Dictionary/Map Get all the keys – listKeys = somemap.keys() Get all the values – listValues = somemap.values() Other methods – clear – empty dictionary – items – return (key,value) pairs – Iteritems – return (key,value) pairs more efficiently – update – update with another dictionary

Change Astrachan’s value somemap[“Astrachan”] = Coffee Mocha

Value could be a set or list

Back to Popular Name Problem: Given a list of names, determine the most popular first name and print that name with all of its last names. Input: Names are always two words, names are in a file. If multiple names are on the same line they are separated by a “:” Output: Most popular first name, followed by a “:”, followed by corresponding last names separated by a blank

Now use a dictionary/map We will write three maps for practice –First name to count of corresponding last names –First name to list of corresponding last names –First name to set of corresponding last names Which map is most useful to solve this problem?

Compare Using two parallel lists? Using one dictionary/map