Skip to content

Instantly share code, notes, and snippets.

@sebastianschramm
Last active August 21, 2022 11:32
Show Gist options
  • Save sebastianschramm/9279aa9b929ece84b2aabde89ca13284 to your computer and use it in GitHub Desktop.
Save sebastianschramm/9279aa9b929ece84b2aabde89ca13284 to your computer and use it in GitHub Desktop.
How to initialize a dictionary from a list of keys?
feature_names = ["sepal_length", "sepal_width", "petal_length", "petal_width"]
default_type = float
feature_map = dict.fromkeys(feature_names, default_type)
"""
>>> feature_map
{'sepal_length': <class 'float'>, 'sepal_width': <class 'float'>,
'petal_length': <class 'float'>, 'petal_width': <class 'float'>}
"""
@sebastianschramm
Copy link
Author

dependencies: python3.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment