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

#print keys and values from the dictionary

for k, v in dic.items():
  print(k, v)

Example 3: how to get the key for a value in a dictionary in python

# function to return key for any value 
def get_key(val): 
    for key, value in my_dict.items(): 
         if val == value: 
             return key 
  
    return "key doesn't exist"
  
# Driver Code 
  
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()) #prints keys and values
print(dictionary.keys()) #prints keys
print(dictionary.values()) #prints values