💻 Computer Science · Topic 29 of 80

Dictionaries and Maps

Dictionaries map keys to values.

Interactive labFollow the idea step by step

About this topic

A dictionary, also called a map, stores data as key and value pairs. Instead of looking up an item by position, you look it up by its key, such as a word to find its definition or a username to find a profile. Keys must be unique, and values can be anything.

For example, ages = {Ana: 15, Ben: 16} lets you write ages[Ana] to get 15. You can add a new pair, change a value, delete a pair and check whether a key exists. Dictionaries are usually implemented with hash tables, so lookups are very fast even with millions of entries.

They suit data with labels: a shopping cart mapping item to quantity, a phone book, a count of how often each word appears in a text, or the JSON data used by websites. A common mistake is asking for a key that does not exist, which causes a key error, so check first or use a default. Another is thinking order matters; in many languages the order of pairs is not guaranteed. Choose a list when order matters and a dictionary when names matter.

Key ideas

  1. Fast lookup by key
  2. Keys must be unique
  3. Used for JSON

Quick check

Use cases: where Dictionaries and Maps helps

Computing ideas run phones, search engines, games and the wider internet.

Frequently asked questions

What is Dictionaries and Maps?

Dictionaries map keys to values.

What will I learn in Dictionaries and Maps?

Fast lookup by key. Keys must be unique. Used for JSON.

Is Dictionaries and Maps part of Computer Science?

Yes. It is one of 80 Computer Science topics on LearnViz HighSchoolEdu, with 3 key ideas, a live animation and a quick check.

Does the Dictionaries and Maps lab work on a phone or tablet?

Yes. The animation resizes to fit your screen and supports touch, so you can drag, tap and slide with your finger.

How should I study Dictionaries and Maps?

Read the summary and key ideas first, play with the interactive lab to see the idea in motion, then answer the quick check. If you get a question wrong, go back to the key idea it tests.

Do I need an account, and is my progress saved?

No account is needed. Marking a topic as learned is saved in your own browser, so it stays on that device and is not sent to a server.

More in Computer Science