Python Data Structures (Dictionary)

Selin Yazıcıoğlu
2 min readJul 14, 2022

--

Hello guys! I will mention the dictionary which is data structures in this article. I will code on Visual Studio Code. Okay, let’s start!

I got this image from the PyShark site.

Dictionary

I would like to mention the features of the dictionary in Python. There are many features. These,

Key—value concepts are in the dictionary.

  • {} is defined with parentheses. The key value pair is separated by commas.
  • It’s unordered. Unable to access with index. Values are accessed via key.
  • It’s mutable. Allows insertion and subtraction. Key’s value can change.
  • It may contain different data types such as string, float, integer etc.
  • Key values can be unique, value duplicated.

I want to give a simple example how you can create to dictionary.

Empty dict

I showed you how you can create to empty dictionary on Visual Code Studio. Also, you can check that I shared it as a gist on Github.

my_dict = {}
print(my_dict)
print(type(my_dict))
Output:
{}
<class 'dict'>

Access to Elements

You can access elements in two different ways in the dictionary.

  • [key]
  • get(key)

Adding Elements

There are many ways to add elements to a dictionary. Let’s do it!

Deleting Elements

  • del key
  • clear()
  • del dict_name
  • pop(key)
  • popitem()

Merging two dictionary

  • update()
  • **

Copying

  • = operatörü
  • copy()
  • dict()

Thus, I finished data structures in Python. If you want to do more practice then you can check https://github.com/Selin-Y/python-projects/blob/main/Exercise%20Dictionary/Exercise_Dictionary.py my related dictionary exercises on Github.

I hope while you’re reading my article you can enjoy it!

See you on another topic :)

If you want, you can follow me at these links:

--

--