python get values of dictionary code example
Example 1: python get dictionary keys
newdict = {1:0, 2:0, 3:0}
newdict.keys()
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')
dict.get('volume', 'The key was not found')
Example 4: get a value from a dictionary python
dict = {'Name': 'Zabra', 'Age': 7}
print "Value : %s" % dict.get('Age')
print "Value : %s" % dict.get('Education', "Never")
Example 5: get dictionary in array python by value
>>> dicts = [
... { "name": "Tom", "age": 10 },
... { "name": "Mark", "age": 5 },
... { "name": "Pam", "age": 7 },
... { "name": "Dick", "age": 12 }
... ]
>>> next(item for item in dicts if item["name"] == "Pam")
{'age': 7, 'name': 'Pam'}