ReferenceDictionary methods
dict.fromkeys()
Builds a dictionary from keys, all sharing one value.
Signature
dict.fromkeys(keys, value=None)Parameters
| Name | Means |
|---|---|
keys | an iterable of keys |
value | the value each gets |
Returns
A new dict.
Example
Python
print(dict.fromkeys("ab", 0))
print(list(dict.fromkeys(["a", "b", "a"])))Output
{'a': 0, 'b': 0}
['a', 'b']