Python Dictionary constructor initialized with keyword argument list

Construct a Python Dictionary object using a keyword argument list

Dictionary Updated 10 Sep 2016 1 min read

Overview

  • A Python dictionary object with values popualated onto it can be created by calling the constructor dict() with keyword arguments.
  • Each keyword argument becomes a key of type string in the newly created dictionary and the value of the keyword argument becomes the value of the key.

Example

python
#Example Python program that creates

            #a dictionary by calling the dict constructor

            #with keyword arguments

            langVsAuthor = dict(CPlusPlus = "BjarneStroustrup",

                                Python = "GuidovanRossum",

                                Fortran = "JohnWBackus");

            print("Programming languages and their authors:");

            print(langVsAuthor);

Output

Output
Programming languages and their authors:

            {'CPlusPlus': 'BjarneStroustrup', 'Python': 'GuidovanRossum', 'Fortran': 'JohnWBackus'}