The values() function in python returns the view object of all the available values in the dictionary as in the form of a list. Actually, it provides a dynamic view of dictionary values.
dictionary.values()
values() method doesn't take any parameters. The result values of this method are stored in a reversed manner.
Any changes in the dictionary also reflect the values of the view object.
Input | Return Value |
---|---|
dictionary | view object |
# random fruits dictionary
fruits = { 'mango': 5, 'banana': 4, 'strawberry': 3 }
Output:
dict_values([5, 3, 4])
# random fruits dictionary
fruits = { 'mango': 5, 'banana': 4, 'strawberry': 3 }
keyvalues = fruits.values()
print('Original list:', keyvalues)
# delete an item from dictionary
del[fruits['mango']]
print('Updated list:', keyvalues)
Output:
Original list: dict_values([5, 3, 4]) Updated list: dict_values([3, 4])