I am trying to print the key and value from a list of dictionaries, and I want the output to appear like this.
first_name - Michael, last_name - Jordan
first_name - John, last_name - Rosales
first_name - Mark, last_name - Guillen
first_name - KB, last_name - Tonel
this is the code I wrote
students = [
{'first_name': 'Michael', 'last_name' : 'Jordan'},
{'first_name' : 'John', 'last_name' : 'Rosales'},
{'first_name' : 'Mark', 'last_name' : 'Guillen'},
{'first_name' : 'KB', 'last_name' : 'Tonel'}
]
def listd (somelist):
for key , value in students:
print(key, '-', value)
print (listd(students))
and i get the output with only keys not values
first_name - last_name
first_name - last_name
first_name - last_name
first_name - last_name
None
what is the mistake I made and how can I view both keys and values?
https://stackoverflow.com/questions/5904969/how-to-print-a-dictionarys-key – Alan Kersaudy May 25 '21 at 17:49