Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
Output of Python Programs | Set 24 (Dictionary)
Next article icon

Python program to print the dictionary in table format

Last Updated : 06 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Given a Dictionary. The task is to print the dictionary in table format.

Examples:

Input: 
{1: ["Samuel", 21, 'Data Structures'], 
2: ["Richie", 20, 'Machine Learning'], 
3: ["Lauren", 21, 'OOPS with java'], 
}
Output: 
NAME AGE COURSE 
Samuel 21 Data Structures 
Richie 20 Machine Learning 
Lauren 21 OOPS with java 

Method 1: Displaying results by iterating through values. 

Python3
# Define the dictionary dict1 = {}  # Insert data into dictionary dict1 = {1: ["Samuel", 21, 'Data Structures'],          2: ["Richie", 20, 'Machine Learning'],          3: ["Lauren", 21, 'OOPS with java'],          }  # Print the names of the columns. print("{:<10} {:<10} {:<10}".format('NAME', 'AGE', 'COURSE'))  # print each data item. for key, value in dict1.items():     name, age, course = value     print("{:<10} {:<10} {:<10}".format(name, age, course)) 

Output
NAME       AGE        COURSE     Samuel     21         Data Structures Richie     20         Machine Learning Lauren     21         OOPS with java 

Method 2: Displaying by using a matrix format 
 

Python3
# define the dictionary dict1 = {}  # insert data into dictionary dict1 = {(0, 0): 'Samuel', (0, 1): 21, (0, 2): 'Data structures',          (1, 0): 'Richie', (1, 1): 20, (1, 2): 'Machine Learning',          (2, 0): 'Lauren', (2, 1): 21, (2, 2): 'OOPS with Java'          }  # print the name of the columns explicitly. print(" NAME ", " AGE ", "  COURSE ")  # Iterate through the dictionary # to print the data. for i in range(3):      for j in range(3):         print(dict1[(i, j)], end='   ')      print() 

Output
 NAME   AGE    COURSE  Samuel   21   Data structures    Richie   20   Machine Learning    Lauren   21   OOPS with Java    

Method 3: Displaying by using zip format 

Python3
# define the dictionary dict1 = {}  # insert data into dictionary. dict1 = {'NAME': ['Samuel', 'Richie', 'Lauren'],          'AGE': [21, 20, 21],          'COURSE': ['Data Structures', 'Machine Learning', 'OOPS with Java']}  # print the contents using zip format. for each_row in zip(*([i] + (j)                       for i, j in dict1.items())):      print(*each_row, " ") 

Output
NAME AGE COURSE   Samuel 21 Data Structures   Richie 20 Machine Learning   Lauren 21 OOPS with Java   


Next Article
Output of Python Programs | Set 24 (Dictionary)

K

KaranGupta5
Improve
Article Tags :
  • Python
  • Python Programs
  • python-dict
Practice Tags :
  • python
  • python-dict

Similar Reads

  • Output of Python Program - Dictionary (set 25)
    Prerequisite: Dictionaries in PythonThese question sets will make you conversant with Dictionary Concepts in Python programming language. Question 1: Which of the following is true about Python dictionaries? A. Items are accessed by their position in a dictionary. B. All the keys in a dictionary mus
    3 min read
  • How to Print a Dictionary in Python
    Python Dictionaries are the form of data structures that allow us to store and retrieve the key-value pairs properly. While working with dictionaries, it is important to print the contents of the dictionary for analysis or debugging. Example: Using print Function [GFGTABS] Python # input dictionary
    3 min read
  • Output of Python Programs | Set 24 (Dictionary)
    Prerequisite : Python-Dictionary1. What will be the output? [GFGTABS] Python dictionary = {"geek":10, "for":45, "geeks": 90} print("geek" in dictionary) [/GFGTABS]Options: 10FalseTrueErrorOutput:3. TrueExplanation: in is used to check the key exist in dictiona
    2 min read
  • Output of Python Programs | (Dictionary)
    Prerequisite: Dictionary Note: Output of all these programs is tested on Python3 1.What is the output of the following of code? a = {i: i * i for i in range(6)} print (a) Options: a) Dictionary comprehension doesn’t exist b) {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6:36} c) {0: 0, 1: 1, 4: 4, 9: 9, 16
    2 min read
  • How to Print Dictionary Keys in Python
    We are given a dictionary and our task is to print its keys, this can be helpful when we want to access or display only the key part of each key-value pair. For example, if we have a dictionary like this: {'gfg': 1, 'is': 2, 'best': 3} then the output will be ['gfg', 'is', 'best']. Below, are the me
    2 min read
  • Dictionary Programs involving Lists - Python
    Dictionaries and lists are two of the most commonly used data structures in Python, and often, we need to work with both together. Whether it's storing lists as dictionary values, converting lists into dictionaries, filtering dictionary data using lists, or modifying dictionary values dynamically, P
    2 min read
  • Python Program to Convert Matrix to String
    Program converts a 2D matrix (list of lists) into a single string, where all the matrix elements are arranged in row-major order. The elements are separated by spaces or any other delimiter, making it easy to represent matrix data as a string. Using List ComprehensionList comprehension provides a co
    2 min read
  • Python program to sort Dictionary by Key Lengths
    Given Dictionary, sort by its key lengths. Input : test_dict = {"Gfg" : 4, "is" : 1, "best" : 0, "for" : 3, "geeks" : 3} Output : {'is': 1, 'Gfg': 4, 'for': 3, 'best': 0, 'geeks': 3} Explanation : 2 < 3 = 3 < 4 < 5, are sorted lengths in order. Input : test_dict = {"Gfg" : 4, "for" : 3, "ge
    4 min read
  • Python Program to display keys with same values in a dictionary List
    Given a list with all dictionary elements, the task is to write a Python program to extract keys having similar values across all dictionaries. Examples: Input : test_list = [{"Gfg": 5, "is" : 8, "best" : 0}, {"Gfg": 5, "is" : 1, "best" : 0}, {"Gfg": 5, "is" : 0, "best" : 0}] Output : ['Gfg', 'best'
    5 min read
  • Get Index of Values in Python Dictionary
    Dictionary values are lists and we might need to determine the position (or index) of each element within those lists. Since dictionaries themselves are unordered (prior to Python 3.7) or ordered based on insertion order (in Python 3.7+), the concept of "index" applies to the values—specifically whe
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences