how to print values from dictionary python code example

Example 1: printing python dictionary values

#print keys and values from the dictionary

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

Example 2: howe to print all values and keysin d

for i in d:
    print d.keys(i), d.values(i)

Example 3: how to print a value from a dictionary in python

dictionary={
  
    "Jeff":{
      	"lastname":"bobson",
        "age":55,
        "working":True
    },
  
    "James":{
      	"lastname":"Bobson",
        "age":34,
        "working":False
    }
}

# For a good format:

for i in dictionary:
    print(i, ":")
    for j in dictionary[i]:
        print("  ", j, ":", dictionary[i][j])
    print()
        

# Output:

Jeff :
   lastname : bobson
   age : 55
   working : True
   
James :
   lastname : Bobson
   age : 34
   working : False
    
# For just a quick reading:

for k, v in dictionary.items():
  print(k, v)
  
# Output: 

Jeff {'lastname': 'bobson', 'age': 55, 'working': True}
James {'lastname': 'Bobson', 'age': 34, 'working': False}

Example 4: print key of dictionary python

for key, value in mydic.iteritems() :
    print key, value