i want to run this code
listf = [
{"name":"akram"}
]
for i in listf:
print(listf["name"])
and this eroor happend
line 5, in <module>
print(listf["name"])
TypeError: list indices must be integers or slices, not str
but in another code from another user :
students = [
{"name": "Hermione", "house": "Gryffindor", "patronus": "Otter"},
{"name": "Harry", "house": "Gryffindor", "patronus": "Stag"},
{"name": "Ron", "house": "Gryffindor", "patronus": "Jack Russell terrier"},
{"name": "Draco", "house": "Slytherin", "patronus": None},
]
for student in students:
print(student["name"], student["house"], student["patronus"], sep=", ")
and it run normal with the output :
Hermione, Gryffindor, Otter
Harry, Gryffindor, Stag
Ron, Gryffindor, Jack Russell terrier
Draco, Slytherin, None