A Python *dictionary* is a un-ordered collection of Python objects (contrast with strings, lists, and tuples which are ordered sequences).
What is new and particularly useful about dictionaries is that they can be indexed using any immutable object (unlike strings, lists and tuples that can only be indexed using integers).
Because it is a collection (like strings, lists, and tuples) it shares characteristics such as iteration (*for*) and membership (*in*)
as well as functions such as len().
Dictionaries are *mutable* (like lists).

A Python *set* is like a mathematical set that you should be familiar with: an un-ordered collection of unique objects. Set operations are the expected ones from mathematics: union, intersection, etc.
Because it is a collection it shares characteristics such as iteration (*for*) and membership (*in*)
as well as functions such as len().
Sets are *mutable*.

Chapter 9: Dictionaries & Sets

- Dictionaries
- Dictionaries (Video I, Video II)
- Sets (Video I, Video II)
- Comprehensions are a convenient way to build collections (Video )
- Examples using
*dictionaries* - Benford's Law (Video)
- Patterns
- Chapter 9 Exercises on Mimir.
- Lab08 (do pre-lab first on D2L)
- Project07

A dictionary is a collection of pairs of Python objects: the pairs have the form *key:value* (note the colon ":"), the pairs are separated by commas and the collection is delimited by curly brackets. Any mixture of objects is allowed for a value; only an immutable can be a key.

Python sets are like mathematical sets: a collection of unique objects within curly braces.

Benford's Law (Wikipedia) refers to the frequency distribution of digits in many (but not all) real-life sources of data. In this distribution, the number 1 occurs as the leading digit about 30% of the time, while larger numbers occur in that position less frequently: 9 as the first digit less than 5% of the time.

How to build a dictionary to count items:

a_dict = {} # start with an empty dictionary for item in collection: if item not in a_dict: a_dict[item] = 1 # initialize else: # item is in a_dict a_dict[item] += 1 # incrementTo build a dictionary of lists: initialize to an empty list and append.