Introduction & Implementation of Dictionary in Python

Lesson 14/20 | Study Time: 10 Min
  • Dictionary is an unordered collection of key-value pairs.

    Real word dictionaries are a good analogy to understand them: they contain a list of items(words), and each item has a key(the word) and a value(the word’s meaning).

    It generally is used when we have a huge amount of data.

    It is defined within braces, with each item being in the form of key: value pair. Syntax –

    my_dict = {
    "key1":"value1",
    "key2":"value2",}

Tutorial on Dictionaries

For the time being, ignore the video after 4 minutes and 18 seconds. Don’t worry if you don’t understand the topics after 4 minutes and 18 seconds. You will learn that soon.


  • The keys in a dictionary must always be unique and immutable.
  • This is the reason dictionary keys can be String but not List.
  • On the other hand, Values in a dictionary can be of any datatype and can be duplicated.
  • Dictionary keys are case sensitive, same name but different cases of Key will be treated distinctly.

Example:

image.png

GDPR

When you visit any of our websites, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences or your device and is mostly used to make the site work as you expect it to. The information does not usually directly identify you, but it can give you a more personalized web experience. Because we respect your right to privacy, you can choose not to allow some types of cookies. Click on the different category headings to find out more and manage your preferences. Please note, that blocking some types of cookies may impact your experience of the site and the services we are able to offer.