Lecture Notes for CPSC 121 Fall 2012: Dictionaries and Exam Overview, Study notes of Computer Science

These lecture notes cover the topic of dictionaries in the cpsc 121 fall 2012 course, including their basics, syntax, unique keys, and operations. The notes also provide an overview of exam 3, including its format and covered topics.

Typology: Study notes

2012/2013

Uploaded on 09/28/2013

noob
noob ๐Ÿ‡ฎ๐Ÿ‡ณ

4.4

(25)

105 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lecture Notes CPSC 121 (Fall 2012)
Today
โ€ขExam overview
โ€ขDictionaries
Reading
โ€ขCh 18 (Dictionaries)
Homework
โ€ขHW 11 due
โ€ขReading assignment out
โ€ขExtra credit out
S. Bowers 1 of 6
pf3
pf4
pf5

Partial preview of the text

Download Lecture Notes for CPSC 121 Fall 2012: Dictionaries and Exam Overview and more Study notes Computer Science in PDF only on Docsity!

Today

  • Exam overview
  • Dictionaries

Reading

  • Ch 18 (Dictionaries)

Homework

  • HW 11 due
  • Reading assignment out
  • Extra credit out

Exam 3 overview

Basics

  • 10% of final grade
  • closed book, notes, computer, etc.
  • 5 multi-part questions

Topics

  • Slices
  • Boolean values
  • Comparison operators (==, <=, >=, <, >, !=)
  • Logical operators (and, or, not)
  • Conditionals (if, if-else, if-elif, if-elif-else)
  • While loops
  • Flow charts

Note:

  • tuples and dictionaries will be on the final
  • so final will have some new stuff, but mostly old stuff

Dictionaries

Every key is unique in a dictionary

  • For example:

d = {โ€™aโ€™: 1, โ€™bโ€™: 2, โ€™aโ€™: 3}

d {โ€™aโ€™: 3, โ€™bโ€™: 2}

  • Note the + operator is not supported

Dictionary operations

Dictionaries support many of the same operations as lists

d = {โ€™aโ€™: 1, โ€™bโ€™: 2, โ€™cโ€™: 3}

d[โ€™aโ€™] # subscript 1

d[โ€™dโ€™] = 1 # add a key-value pair d {โ€™aโ€™: 1, โ€™bโ€™: 2, โ€™cโ€™: 3, โ€™dโ€™: 1}

d[โ€™aโ€™] = 2 # set a key value d {โ€™aโ€™: 2, โ€™bโ€™: 2, โ€™cโ€™: 3, โ€™dโ€™: 1}

d.get(โ€™aโ€™) 2

d.get(โ€™eโ€™, 0) # alt value 0

โ€™aโ€™ in d # key in dictionary True

โ€™eโ€™ in d False

โ€™eโ€™ not in d True