
Explores dictionaries as associative arrays in Python 3.6+, along with sets and Json, focusing on idiomatic code, hash maps, serialization, and effective use of the standard library.
Review prerequisites for this course, including functions, unpacking, closures, decorators, iterables, dunder methods, exception handling, and dictionaries, plus setup with pip, virtual environments, Jupyter or cloud notebooks, and GitHub.
Explore dictionaries, aka associative arrays, in Python and how hash tables shape their behavior. Learn that keys must be hashable and that insertion order is preserved by compact dictionaries.
Discover associative arrays by linking keys to values, using dictionaries and hash maps, and practice adding, removing, modifying, and looking up elements efficiently in Python.
Explore Python's built-in hash function, how hashes differ for ints, floats, strings, and tuples, and why only hashable, typically immutable, types can serve as dictionary keys or set members.
Explore creating dictionaries with literals and constructors, understand hashing and key equality, and use tuples or functions as keys, plus dictionary comprehension and from keys.
Master common dictionary operations in Python: assign and update keys, use get with defaults, test membership, and remove items with del, pop, popitem, or setdefault, noting insertion order since 3.6.
Explore Python dictionaries and sets with practical operations: create dicts via zip and from keys, use get with defaults, handle missing keys, and apply setdefault and pop.
Explore dictionary views—keys, values, and items—and how they are dynamic, iterable, and reflect insertion order. Learn their set-like behavior, non-updatability, and common operations like union, intersection, and difference.
Explore dictionary views in Python, including keys, values, and items; learn to perform set-like operations (union, intersection, difference) on views, iterate efficiently, and build dictionaries with comprehensions.
Explore how to use custom classes as dictionary keys by implementing equality and hashing, and understand hash tables, probe sequences, and how collisions affect insertion and lookup.
Sort a dictionary by its values using dict.items and sorted with a key lambda on the second element, then build the result with dict() instead of a comprehension.
Finds common keys between two dictionaries and returns a dictionary mapping each to a tuple of their values, using the keys intersection and a dict comprehension.
Compute the union and intersection of dictionary keys, extract the non-common keys, and build a dictionary with each key's values from three dictionaries, defaulting to zero.
Explore the fundamentals of sets as unordered collections of distinct elements, learn set membership, and use Python operators and functions to perform unions, intersections, complements, and cardinality.
Explore how Python sets support membership tests, unions, intersections, and differences, and compare mutable sets with frozen sets, emphasizing hashability and fast lookups.
Learn how to create and use sets in Python, including literal notation, the set constructor, and set unpacking, to obtain unique hashable elements from iterables.
Master common set operations: cardinality and membership tests with in and not in, add and remove elements, and discard, pop, and clear, noting no ordering and hash-based efficiency.
Learn common Python set operations—union, intersection, difference, and symmetric difference—using both operators and methods with iterables, plus containment tests and subset/superset relationships.
Explore set operations such as intersection, union, disjoint tests, differences, and symmetric differences using sets and iterables, with subsets, supersets, and practical caveats with lists.
Explore update operations on sets, mutating the left-hand set with union, intersection, difference, and symmetric difference, while noting sets have no ordering and non-associativity of differences.
Explore update operations on sets, including intersection, union, difference, and symmetric difference, and compare mutating methods with operator forms.
Explore copying sets in python by distinguishing shallow and deep copies, understanding hashability and object identity, and using set operations to test containment and mutation effects.
Explore frozen sets, the immutable counterparts of sets that remain hashable when elements are hashable and can be used as dictionary keys. Understand copy behavior and nonmutating set operations.
Explore how dictionary views evolve from lists to light-weight, set-like iterables for keys, values, and items, and learn safe iteration and set-like operations.
Explore how dictionary views for keys, values, and items reflect changes to the underlying dictionary, and why mutating a dict during iteration triggers dictionary changed size during iteration errors.
Validate nested dictionaries against a template to ensure json-like data matches expected keys and types, using a manual validator, recursion, and error handling.
Explore a recursive approach to validating nested dictionaries and JSON structures against a template, with key matching, type checks, breadcrumb path, and exception-driven error handling.
Explore serialization and deserialization to persist and transmit data, focusing on dictionaries and json; learn how to convert objects into json strings, handle dates, and briefly compare pickle and marshmallow.
Learn how Python pickling serializes and deserializes objects, especially dictionaries. Explore binary dump and load variants, equality versus identity, and how shared or recursive objects are preserved.
Explore how Python's pickle module serializes and deserializes dictionaries and basic data types, including dumps and loads, and examine security risks from untrusted pickled objects.
Explore json serialization basics, a text-based, human-readable format for web APIs, and safe deserialization. Learn Python's json module with dumps, dump, loads, and load to serialize dictionaries and nested structures.
Explore Json serialization in Python by using the Json module with dumps and loads to convert dictionaries to Json strings, handle types, and address non-serializable objects with custom serialization.
Learn to serialize complex Python objects to JSON by implementing custom formatters, using ISO 8601 for datetimes, and applying single dispatch for extensible types.
Explore Python's json encoder and dumps options, including skip keys, indent, separators, and sort keys to control serialization. Create a json encoder by subclassing JsonEncoder to enforce consistency across dumps.
Explore customizing Json encoder in Python by subclassing the encoder, using dumps with a class, and encoding date times with iso format while delegating unknown types.
Explore custom json decoding in python using load and loads, with object_hook and object_pairs_hook to deserialize complex types, apply schemas, and handle iso date time and decimals.
Learn to decode json in Python with loads and load, use a custom object_hook to deserialize date time and fractions via a defined schema, and handle nested structures.
Learn how to implement a custom json decoder by inheriting and overriding the decode method to parse the entire json string, using the class argument with load/loads for consistent deserialization.
Create a custom json decoder to parse json strings into dictionaries and objects, handle points schemas, and convert nested structures with optional decimal parsing.
Demonstrate serialization and deserialization with YAML using PyYAML, covering dictionaries, lists, and Python objects, and discuss safe_load versus load, pickle risks, and optional Marshmallow integration for object mapping.
Explore a fast one-way serialization library for Python, with schemas for person and movie objects, and compare it to marshmallow, including Json and Yaml outputs.
Practice serializing and deserializing dictionaries of stock and trade objects with Python's standard library json, using a custom encoder for date, datetime, and Decimal values, and compare with marshmallow.
Learn how to implement a custom json encoder and decoder for serializing and deserializing stock and trade objects within an activity dictionary, with recursive decoding and equality checks.
Use Marshmallow to serialize and deserialize stocks, trades, and activities with schemas, nested fields, and stringified decimals, mastering dumps, loads, and post_load construction.
Explore specialized dictionaries in the Python standard library, including default dict, ordered dict, counter, chain map, and user dict. Learn their behaviors, ordering, and use cases for custom dictionary types.
Explore how default dict handles missing keys by auto-creating a default with a zero-argument callable, a factory, and compare its behavior to get.
Explore defaultdict in Python by comparing get versus automatic key creation and counting character occurrences with defaultdict. Learn lambda factories and partials, and implement a decorator to track calls.
examine how ordered dict preserves insertion order and adds pop item and move to end. compare its behavior with regular dict and the deck for use.
Explore dictionaries and the Counter from collections to maintain counters, update counts from others or iterables, and find the most common items.
Learn to count and analyze data with Python's collections.Counter: count characters and words, find the most common items, and perform updates, arithmetic, and lazy iteration.
Explore how chain maps combine dictionaries efficiently, compare unpacking with chain map, and learn to insert, update, delete, and merge configurations without duplicating data.
Learn to build custom dictionaries in Python with user dict to enforce real numbers and truncation, compare with dict inheritance, implement a limited dict for red, green, blue keys 0–255.
Merge dictionaries to compute frequencies using defaultdict or counter, then count eye colors with zeros for missing values, and practice recursive chain map merging of common dev prod json configurations.
Learn to count eye colors with collections.Counter, ensuring zero counts for missing colors by pre initializing or merging zero values. Return results in most common order when needed.
Explore loading environment-specific JSON settings and merging them with common defaults by recursively merging nested dictionaries, using a recursive chain map approach to override values.
This course is an in-depth look at Python dictionaries.
Dictionaries are ubiquitous in Python. Classes are essentially dictionaries, modules are dictionaries, namespaces are dictionaries, sets are dictionaries and many more.
In this course we'll take an in-depth look at:
associative arrays and how they can be implemented using hash maps
hash functions and how we can leverage them for our own custom classes
Python dictionaries and sets and the various operations we can perform with them
specialized dictionary structures such as OrderedDict and how it relates to the built-in Python3.6+ dict
Python's implementation of multi-sets, the Counter class
the ChainMap class
how to create custom dictionaries by inheriting from the UserDict class
how to serialize and deserialize dictionaries to JSON
the use of schemas in custom JSON deserialization
a brief introduction to some useful libraries such as JSONSchema, PyYaml and Serpy
***** Prerequisites *****
Please note that this is a relatively advanced Python course, and a strong knowledge of some topics in Python is required.
Beyond the basics of Python (loops, conditional statements, exception handling, built-in data types, creating classes, etc), you should also have an in-depth understanding of the following topics:
functions and functional programming (recursion, *args, **kwargs, zip, map, sorted, any, all, etc)
lambdas, closures and decorators (including standard decorators such as @singledispatch, @wraps, etc)
iterables, iterators, generators and context managers
named tuples
variable scopes and namespaces (globals, locals, etc)
For this course you will also need to install some 3rd party libraries, so you need to be comfortable with doing this using the tool of your choice (e.g. pip, conda, etc)
Finally, most of the code in this course is illustrated using the freely available Jupyter Notebooks, so you will need that as well.