VOOZH about

URL: https://www.geeksforgeeks.org/python/python-create-dictionary-from-list-with-default-values/

⇱ Python Create Dictionary from List with Default Values - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Python Create Dictionary from List with Default Values

Last Updated : 23 Jul, 2025

Creating a dictionary from a list with default values allows us to map each item in the list to a specific default value. Using dict.fromkeys(), we can quickly create a dictionary where all the keys from the list are assigned a default value, such as None or any other constant.

Using dict.fromkeys()

This method creates a dictionary where each key from the list is associated with a default value.


Output
{'a': 0, 'b': 0, 'c': 0, 'd': 0}

Explanation

  • The fromkeys() method creates a dictionary using the provided list of keys and assigns each key the default value passed.

Using Dictionary Comprehension

Dictionary Comprehension gives more control over how the keys are mapped to values.


Output
{'a': 0, 'b': 0, 'c': 0, 'd': 0}

Explanation: A dictionary comprehension loops through the keys list and assigns each key the default_value.

Using a for loop

You can manually iterate through the list and add each element to the dictionary with the default value.


Output
{'a': 0, 'b': 0, 'c': 0, 'd': 0}

Explanation: for loop iterates over the keys list and assigns the default value to each key in the dictionary.

Comment