I have a few dictionaries that I added into one larger dictionary.
violet = {"animal":"cat","owner":"Theresa"}
lucy = {"animal":"cat","owner":"Theresa"}
button = {"animal":"rabbit","owner":"Theresa"}
our_animals = {}
our_animals["Violet"] = violet
our_animals["Lucy"] = lucy
our_animals["Button"] = button
for animal in our_animals:
print(animal,"is a:")
for kind, owner in our_animals.values():
print(kind,"owned by", owner)
This just gave me this
Violet is a:
animal owned by owner
animal owned by owner
animal owned by owner
Lucy is a:
animal owned by owner
animal owned by owner
animal owned by owner
Button is a:
animal owned by owner
animal owned by owner
animal owned by owner
In my mind I've now created a dictionary in which
"Violet" is a key and the dictionary {"animal":"cat,"owner":"Theresa"} is the value associated with "Violet". In the code above I was attempting to iterate over the values of the dictionary which is itself a value. I wanted my output to be something like.
Violet is a:
cat owned by Theresa
Lucy is a:
cat owned by Theresa
Button is a:
rabbit owned by Theresa
I'm only a month into learning python so any teaching moment would be greatly appreciated. Thank you in advance!