Programming Meets Fitness – Part 6

Part 1 –  Preparation

Part 2 – Introduction (Basics)

Part 3 – Introduction (Lists)

Part 4 – Advance (Lists)

Part 5 – Introduction (If Statements)

Part 6 – Introduction (Dictionaries)


Dictionaries is a feature use for a key-value pair. This is very helpful for tasks utilizing records/data. Just like the previous article, code samples are going to be in representation of the game “Dota2”.

A sample view of a dictionary in Python:

As you can see in the example, a dictionary use {}  while a list uses [] . Don’t confuse yourself with the symbols being used.

Calling a key-value pair in Python:

Expected Output:

In case you wanted to observe capitalization for a “value” returns, you need to take note that appending title()  , lower()  , upper()  should be on the  outside the [] .

Calling a key-value pair in Python (while observing Naming convention):

Expected Output:

Also, a “value” on a dictionary is replaceable. Just add a variable corresponding to the “key” and the “value” you wanted to set.

Replacing a key-value in Python:

Expected Output:

Deleting a key-value pair is through the command del  which is widely used in Python.

Expected Output:

There is more task we can execute on dictionaries. We will explore more of this on the next part of this section.

Tags : , , , ,