A dictionary (type dict) stores key-value pairs. Instead of looking items up by numeric position, as with a list, you look them up by a meaningful key, the way you look up a word in a real dictionary to find its definition. You write a dictionary in curly braces with a colon between each key and its value and commas between pairs: ages = {"Ana": 31, "Ben": 27}. An empty dictionary is {} or dict(). Note that {} is an empty dict, not an empty set. You can also build one from pairs, as in dict([("a", 1), ("b", 2)]), or with keyword arguments, as in dict(a=1, b=2).
Keep reading for free
Create a free StudyToCert account to read the rest of this lesson: 7 more sections, 7 key terms, a real-world example, an exam tip and self-check questions. Every lesson, lab and practice test is free with an account.