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
# Python program to get
# dictionary keys as list
def getList(dict):
list = []
for key in dict.keys():
list.append(key)
return list
# Driver program
dict = {1:'Geeks', 2:'for', 3:'geeks'}
print(getList(dict))
xxxxxxxxxx
print(d.get('key5', 'NO KEY'))
# NO KEY
print(d.get('key5', 100))
# 100
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)