print python dictionary keys and values code example
Example 1: print key of dictionary python
for key, value in mydic.items() :
print (key, value)
Example 2: printing python dictionary values
for k, v in dic.items():
print(k, v)
Example 3: how to get the key for a value in a dictionary in python
def get_key(val):
for key, value in my_dict.items():
if val == value:
return key
return "key doesn't exist"
my_dict ={"java":100, "python":112, "c":11}
print(get_key(100))
print(get_key(11))
Example 4: print key of dictionary python
for key, value in mydic.iteritems() :
print key, value
Example 5: python dict print keys
print(dictionary.items())
print(dictionary.keys())
print(dictionary.values())