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}
Rick Donato

Want to become a programming expert?

Here is our hand-picked selection of the best courses you can find online:
Python Zero to Hero course
Python Pro Bootcamp
Bash Scripting and Shell Programming course
Automate with Shell Scripting course
The Complete Web Development Bootcamp course
and our recommended certification practice exams:
AlphaPrep Practice Tests - Free Trial