Working with Python dictionaries: a cheat sheet

Working with Python dictionaries: a cheat sheet

In this tutorial, we'll learn Working with Python dictionaries: a cheat sheet. Accessing, editing and looping through dictionary items.

Accessing, editing and looping through dictionary items

Dictionaries in Python are a collection of key-value pairs — meaning every item in the dictionary has a key and an associated value.

If we want to write down prices of some items in a grocery store, normally we will note them on a piece of paper like this:

eggs - 4.99
banana - 1.49
cheese- 4.5
eggplant - 2.5
bread - 3.99

In Python dictionary lingo, the name of each item is “key” and the associated price is “value” and they appear in pairs. We can represent the same in a Python dictionary data structure as follows:

{"eggs": 4.99,
"banana": 1.49,
"cheese": 4.5,
"eggplant": 2.5,
"bread": 3.99}

Notice the differences. In the dictionary

  • each key is within quotation marks because they are strings
  • the associated values are not quoted because they are numeric
  • keys and values are separated by a colon (:)
  • the items are comma-separated

dictionary python artificial-intelligence dictionaries python dictionary working with python dictionaries

What is Geek Coin

What is GeekCash, Geek Token

Best Visual Studio Code Themes of 2021

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Start a Career in Machine Learning and Artificial Intelligence

Enroll now at best Artificial Intelligence training in Noida, - the best Institute in India for Artificial Intelligence Online Training Course and Certification.

top 30 Python Tips and Tricks for Beginners

In this post, we'll learn top 30 Python Tips and Tricks for Beginners

7 Ways Artificial Intelligence Can Help Make Your Time at Home

Enroll now at best Artificial Intelligence training in Noida, - the best Institute in India for Artificial Intelligence Online Training Course and Certification.

Lambda, Map, Filter functions in python

You can learn how to use Lambda,Map,Filter function in python with Advance code examples. Please read this article

Artificial Intelligence with Python | Artificial Intelligence Tutorial

"Artificial Intelligence With Python" will provide you with a comprehensive and detailed knowledge of Artificial Intelligence concepts with hands-on examples.