• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to create a Python Dictionary

by admin

Dictionaries in python are quite similar to arrays in how they look however arrays are indexed by a range of numbers i.e. 1-10, but dictionaries are indexed by their key. You can set these keys to immutable data types only. They can also be known as key pair arrays.

You will be used to seeing this to create a standard array using square brackets.

 test_array = []

If you want to create a dictionary you use curly brackets.

 test_dictionary = {}

The format of a dictionary looks like this.

{'TEST': 1}

With TEST being the key and 1 the pair.

If you want to store values in a dictionary

test_dictionary["KEY"] = "Pair"
Note: You don’t have to just use string other data types in place of each one.

To iterate through a dictionary:

for key, value in test_dictionary.items():
     print('{0} links to {1}'.format(key, value)
Note: Using format when printing strings is considered good practice.

Filed Under: Linux

Some more articles you might also be interested in …

  1. ceph Command Examples in Linux
  2. How to manage File and Directory Permissions/Ownerships in Linux
  3. gnome-software Command Examples in Linux
  4. dvc commit: Record changes to DVC-tracked files in the project
  5. gdalinfo: List various information about a GDAL supported raster dataset
  6. cpufreq-aperf: command not found
  7. How to Find and Delete Empty Directories and Files in Linux
  8. sreport Command Examples in Linux
  9. qm migrate Command Examples in Linux
  10. “helm install” Command Examples

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright