Earn 20 XP


  • 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 –

    1 2 3 4 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