dict.fromkeys()
dict.fromkeys() is a Python method in the Dictionary Methods category. Creates a new dict with keys from iterable and values set to value. The syntax is dict.fromkeys(iterable, value=None). Parameters: iterable — keys to set. Returns: New dict. A typical example: dict.fromkeys(["a", "b"], 0) # {"a": 0, "b": 0}
dict.fromkeys("abc") # {"a": None, "b": None, "c": None}. A close sibling is dict.get(), which returns the value for key if it exists, otherwise returns default. A close sibling is dict.keys(), which returns a view object of all keys in the dictionary. A close sibling is dict.values(), which returns a view object of all values in the dictionary. A close sibling is dict.items(), which returns a view object of all (key, value) pairs as tuples. More about this category: Dictionary methods for key-value operations — get, keys, items, update, and more. For a broader walkthrough, read the Dictionary Methods guide.