find the values of a map in python

In Python, you can get the values of a map or dictionary using the values() function.

main.py
my_map = {"key1": "value1", "key2": "value2", "key3": "value3"}

# get the values of the map
my_values = my_map.values()

print(my_values)  # output: dict_values(['value1', 'value2', 'value3'])
194 chars
7 lines

The values() function returns a view object that contains the values of the map. You can convert it to a list if you want to use it as a list.

main.py
my_list = list(my_values)

print(my_list)  # output: ['value1', 'value2', 'value3']
84 chars
4 lines

You can then iterate over the values or perform any other operation that you want to do with them.

gistlibby LogSnag