Find us on GitHub

Teaching basic lab skills
for research computing

Sets and Dictionaries

Every programmer meets lists (or arrays or matrices) early in her career. Most never meet sets and dictionaries, and that's a shame: for many problems, they're more efficient in both human and machine terms. They're also the basis of some advanced programming techniques that give us much more control over what our programs do and how they do it.

  • A set is an unordered collection of distinct values.
  • Sets are stored using hash tables, which makes them fast, but means their elements can't be modified after being added.
  • A dictionary is an unordered collection of key-value pairs.
  • Use dictionaries to store data that is sparse, irregular, or not intrinsically ordered.
  1. Introduction
  2. Tuples
  3. Storage
  4. Dictionaries
  5. Examples
  6. Nanotech Example
  7. Phylogenetic Trees