xxxxxxxxxx
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)
xxxxxxxxxx
myDict = {
"message": "Hello Grepper!"
}
for key, value in myDict.items():
print(key) #Output: message
print(value) #Output: Hello Grepper!
xxxxxxxxxx
dict = {1: 'a', 2: 'b'}
value = 'a'
key = [x for x in dict.keys() if dict[x] == value][0]
xxxxxxxxxx
# Example dictionary
my_dict = {"name": "John", "age": 25, "country": "USA"}
# Retrieve value for a specific key
key = "age"
value = my_dict.get(key)
# Print the value
print(value)
xxxxxxxxxx
myDict = {
"message": "Hello Grepper!"
}
for key, value in myDict.items():
print(key) #Output: message
print(value) #Output: Hello Grepper!
xxxxxxxxxx
d = {"a":0, "b":1, "c":2}
keys, values = [], []
for k, v in d.items():
keys.append(k)
values.append(v)
print(keys,values)
xxxxxxxxxx
print(d.get('key5', 'NO KEY'))
# NO KEY
print(d.get('key5', 100))
# 100