cps6-111101

cps6-111101 - CompSci 6 Introduction to Computer Science...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
CompSci 6 Introduction to Computer Science November 1, 2011 Prof. Rodger
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Announcements • No Reading for next time, no RQ • Apt-04 out, due Thursday • Today – Writing Dictionaries/maps – Solving one apt EmailsCourse
Background image of page 2
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
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Example • Each student could be mapped to their favorite ice cream flavor
Background image of page 4
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”
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
• Get all the keys – listKeys = somemap.keys() • Get all the values – listValues = somemap.values()
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 01/17/2012.

Page1 / 11

cps6-111101 - CompSci 6 Introduction to Computer Science...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online