Python - Create a Dictonary using List Items as Keys

Below shows you how to create a dictionary using keys from list items using list comprehension. From this we can also set a default value.

>>> keys = ['a','b','c','d']
>>> { x:False for x in keys }
{'a': False, 'c': False, 'b': False, 'd': False}

Tags: Python

About the Author


R Donato

Rick Donato is the Founder and Chief Editor of He currently works as an SDN/NFV Solutions Architect and has a keen interest in automation and the cloud.

You can find Rick on Twitter @f3lix001