Python - Create a dictionary using list with none values

Sometimes you need to create a dictionary from a list where each list element becomes a key with a None value. This is useful for creating placeholder dictionaries or initializing data structures. Python provides several methods to achieve this conversion.

Using dict.fromkeys()

The dict.fromkeys() method creates a dictionary with keys from an iterable and assigns the same value to all keys. By default, it assigns None ?

days = ["Mon", "Tue", "Wed", "Thu", "Fri"]
print("Given list:")
print(days)

result = dict.fromkeys(days)

print("Dictionary with None values:")
print(result)
Given list:
['Mon', 'Tue', 'Wed', 'Thu', 'Fri']
Dictionary with None values:
{'Mon': None, 'Tue': None, 'Wed': None, 'Thu': None, 'Fri': None}

Using zip() and dict()

The zip() function pairs each list element with None values, then dict() converts the pairs to a dictionary ?

days = ["Mon", "Tue", "Wed", "Thu", "Fri"]
print("Given list:")
print(days)

result = dict(zip(days, [None] * len(days)))

print("Dictionary with None values:")
print(result)
Given list:
['Mon', 'Tue', 'Wed', 'Thu', 'Fri']
Dictionary with None values:
{'Mon': None, 'Tue': None, 'Wed': None, 'Thu': None, 'Fri': None}

Using Dictionary Comprehension

Dictionary comprehension provides a concise way to create dictionaries by iterating through the list and assigning None to each key ?

days = ["Mon", "Tue", "Wed", "Thu", "Fri"]
print("Given list:")
print(days)

result = {key: None for key in days}

print("Dictionary with None values:")
print(result)
Given list:
['Mon', 'Tue', 'Wed', 'Thu', 'Fri']
Dictionary with None values:
{'Mon': None, 'Tue': None, 'Wed': None, 'Thu': None, 'Fri': None}

Comparison

Method Readability Performance Best For
dict.fromkeys() High Fastest Simple conversion
zip() + dict() Medium Moderate When you understand pairing
Dictionary comprehension High Good Complex transformations

Conclusion

Use dict.fromkeys() for the simplest and fastest conversion. Dictionary comprehension is best when you need more complex key or value transformations beyond just None values.

Updated on: 2026-03-15T18:18:57+05:30

741 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements