Docsity

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

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