3.2 - Dictionary

Ha Khanh Nguyen (hknguyen)

1. What is a dictionary?

2. Elements of a Dictionary

2.1 Access, insert or set elements

2.2 Delete elements

2.3 Iterators of dict's keys and values

2.4 Merge dictionaries

3. Creating Dictionary From Sequences

3.1 The zip() function

3.2 Unzip!

Given a "zipped" sequence, the zip() function can also be applied in a clevery way to "unzip" the sequence.


Let s be a string that contains a simple mathematical expression, e.g.,

s = '1.5 + 2.1'

s = '10.0-1.6'

s = '3.1*5.8'

s = '4.7 /7.2'

The expression will only have 2 operands and the operator will be one of the following: +, -, * and /.

Write a program that interpret the expression, then evaluate it and store the result in the result variable.

This lecture note is modified from Chapter 3 of Wes McKinney's Python for Data Analysis 2nd Ed.