myDict = {
"message": "Hello Grepper!"
}
for key, value in myDict.items():
print(key) #Output: message
print(value) #Output: Hello Grepper!
d = {"a":0, "b":1, "c":2}
keys, values = [], []
for k, v in d.items():
keys.append(k)
values.append(v)
print(keys,values)
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)]
myDict = {
"message": "Hello Grepper!"
}
for key, value in myDict.items():
print(key) #Output: message
print(value) #Output: Hello Grepper!
myDict={"name":"PythonForBeginners","acronym":"PFB"}
print("Dictionary is:")
print(myDict)
dict_items=myDict.items()
print("Given value is:")
myValue="PFB"
print(myValue)
print("Associated Key is:")
for key,value in dict_items:
if value==myValue:
print(key)
print(d.get('key5', 'NO KEY'))
# NO KEY
print(d.get('key5', 100))
# 100