myDict = {
"comment": "A like if you love learning python with grepper!"
}
myDict["comment"] #retrieves comment if found. Otherwise triggers error
#or if not sure if key is in dictionary, avoid exiting code with error.
myDict.get("comment") #retrieves comment or None if not found in dict
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'
dict = {1: 'a', 2: 'b'}
value = 'a'
key = [x for x in dict.keys() if dict[x] == value][0]
list(prio.keys())[list(prio.values()).index(x)]
dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}
print(dict['Name']) # Zara
print(dict['Age']) # 7
print(d.get('key5', 'NO KEY'))
# NO KEY
print(d.get('key5', 100))
# 100