.fromkeys() method returns a dictionary with a specified set of keys. It can also initialize the entries with a specified value.
keys is an iterable containing the keys for the new dictionary and
value is an optional initial value for the new entries in the dictionary. If
value is not specified, the default initial value for each key will be
The following example creates a new dictionary with an initial value for each key.
Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.
Learn Python on Codecademy
Computer ScienceLooking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
Includes 6 Courses
With Professional Certification