Answers for "how to print something from a dictionary in python"

1

python print dictionary line by line

# Iterate over key/value pairs in dict and print them
for key, value in student_score.items():
    print(key, ' : ', value)
Posted by: Guest on May-28-2020
1

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}
Posted by: Guest on September-07-2020

Code answers related to "how to print something from a dictionary in python"

Python Answers by Framework

Browse Popular Code Answers by Language