April 19, 2024, 11:17 p.m. | Main

DEV Community dev.to

Thefromkeys() method of dicttype is used to create a new dictionary with keys from a given iterable and values pre-filled with a specified default value.


The syntax is as shown below:




dict.setdefault(iterable, value = None)


The items in the created dictionary has the elements from the iterableas keys and the specified valueas the default value. If valueis not given, Nonewill be used.




keys = [1, 2, 3, 4, 5]

d = dict.fromkeys(keys)
print(d)


If the default value is given, the …

create dictionary iterable keys python syntax value values

Seeking Developers and Engineers for AI T-Shirt Generator Project

@ Chevon Hicks | Remote

Software Engineer for AI Training Data (School Specific)

@ G2i Inc | Remote

Software Engineer for AI Training Data (Python)

@ G2i Inc | Remote

Software Engineer for AI Training Data (Tier 2)

@ G2i Inc | Remote

Data Engineer

@ Lemon.io | Remote: Europe, LATAM, Canada, UK, Asia, Oceania

GCP Data Engineer

@ Avant Digital | Delhi, DL, India