get dict values python code example

Example 1: python get dict values as list

food_list=list(data.values())
print(food_list)

Example 2: list of dict values

list(d.values())

Example 3: python get value from dictionary

dict = {'color': 'blue', 'shape': 'square', 'perimeter':20}
dict.get('shape') #returns square

#You can also set a return value in case key doesn't exist (default is None)
dict.get('volume', 'The key was not found') #returns 'The key was not found'

Example 4: how to get the value of key in python

print(dict.get("key"))

Example 5: get a value from a dictionary python

#!/usr/bin/python

dict = {'Name': 'Zabra', 'Age': 7}
print "Value : %s" %  dict.get('Age')
print "Value : %s" %  dict.get('Education', "Never")

Example 6: how to get the value of key in python

print(dict["key"])