How to initialize a dictionary from a list of keys?
The standard dict class has a classmethod .fromkeys which accepts a list of keys and optionally a value. In our example we have a list of feature names that are all from type float. Using fromkeys we can initialize a dictionary with the feature names as keys and value float. If no value is provided in fromkeys, it defaults to None.
dependencies: python3.9
Comments
Post a Comment