How can I extract all values from a dictionary in Python?
If you want all of the values, use this:
dict_name_goes_here.values()
If you want all of the keys, use this:
dict_name_goes_here.keys()
IF you want all of the items (both keys and values), I would use this:
dict_name_goes_here.items()
For Python 3, you need:
list_of_dict_values = list(dict_name.values())
If you only need the dictionary keys 1
, 2
, and 3
use: your_dict.keys()
.
If you only need the dictionary values -0.3246
, -0.9185
, and -3985
use: your_dict.values()
.
If you want both keys and values use: your_dict.items()
which returns a list of tuples [(key1, value1), (key2, value2), ...]
.
Use values()
>>> d = {1:-0.3246, 2:-0.9185, 3:-3985}
>>> d.values()
<<< [-0.3246, -0.9185, -3985]