liveBook · Manning

Map

As explained in Software Engineering for Data Scientists

A dictionary is a mutable mapping data structure that associates unique keys with values for efficient lookup.

A dictionary stores key-value pairs so a key can retrieve its mapped value. It offers a clear alternative to long, repetitive if-else chains. section 3.2.3

Mapping day indexes to names

Instead of testing seven conditions, define one lookup dictionary: days_of_week = {1: "Sunday", 2: "Monday", 3: "Tuesday", 4: "Wednesday", 5: "Thursday", 6: "Friday", 7: "Saturday"}. Retrieve a name with day = days_of_week[day_index]. This reduces the mapping to two clear lines and reduces opportunities for typos. section 3.2.3

Dictionaries also organize data in practical workflows. Stock-price downloads can use ticker symbols as keys and their returned data frames as values, while a separate failures collection records invalid tickers when exception handling allows processing to continue. section 3.6.3

How Software Engineering for Data Scientists covers it

How deep it goes
Explains key-value lookup through short Python examples and stops short of dictionary internals or broader operations.
Examples
Demonstrates weekday-name lookup and ticker-indexed stock-price data, including failures from an invalid ticker.
What you can do after
Apply it via Python to replace repetitive conditionals and store values associated with lookup keys.
How it connects
Connects dictionaries to if-else statements, repetitive code, exception handling, and data frames.

Also explained in

Compare how 49 books explain Map →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Software Engineering for Data Scientists. The section links point to the parts of the book it draws on.