i am a new programmer trying to learn how to code still. I still don't quite know all of the technical info. I am trying to use a for loop on a list of dictionaries, and then inside of that loop, i want to create another loop that enumerates the dictionary keys. Inside of that loop, I then want to print the keys and values. I want the loop to break once the index reaches all of the points.
Dogs_in_Shelter = [{
"type" : "poodle",
"age" : "2",
"size" : "s",
},
{
"type" : "pug",
"age" : "7",
"size" : "m",
},
{
"type" : "lab",
"age" : "10",
"size" : "m",
}
]
for a in Dogs_in_Shelter:
for index, a in enumerate(Dogs_in_Shelter):
while (index <= 2):
print("{} {}".format(index,a["type"]))
index += 1
break
what prints out is:
0 poodle
1 pug
2 lab
0 poodle
1 pug
2 lab
0 poodle
1 pug
2 lab
I want only the first three lines (with the key and value) , not the repetitions. Any help for a learner?
edit Yes there is an easier way without the nesting loops however i still need to have them nested. Thanks!