oldoc63 / learningDS

Learning DS with Codecademy and Books
0 stars 0 forks source link

Python Dictionaries #349

Open oldoc63 opened 1 year ago

oldoc63 commented 1 year ago

A dictionary is an unordered set of key: value pairs.

It provides us with a way to map pieces of data to each other so that we can quickly find values that are associated with one another.

Suppose we want to store the prices of various items sold at a cafe:

In Python we can create a dictionary called menu to store this data:

oldoc63 commented 1 year ago

Notice that:

  1. A dictionary begins and ends with curly braces { and }.
  2. Each item consist of a key ("avocado toast") and a value (6).
  3. Each key: value pair is separated by a comma.

It's considered good practice to insert a space ( ) after each comma, but our code will still run without the space.