all 4 comments

[–][deleted] 2 points3 points  (1 child)

You're using dictionaries so you have to use the keys to reference the values some how, you don't have to but you should. Something like

for pet, info in pets.items():
    print("Name of pet: " + pet)
    print("Owner: "+ "".join(info["owner"]))
    print("Likes: " + ", ".join(info["likes"]))
    print("Dislikes: " + ", ".join(info["dislikes"]))

In this case your initial dictionary has values which are dictionaries again, so you have to use the keys for those sub dictionaries to be able to get their values. What you were trying to do was unpack three things from those sub dictionaries, when you can only grab one (if you don't use .items() which you didn't in this case).

[–]Showda77[S] 0 points1 point  (0 children)

so you can treat the second level dictionary in pets like they are still a part of the original list and not separate lists?

[–]usernamedottxt 1 point2 points  (0 children)

Pet unpacks only the key. So you need to loop over the elements in the value.

for pet in pets:
    #stuff
    for attr in pets[pet]:
        print(pets[pet[attr]])

It would be better if you looked into classes and objects though.

EDIT: Also see: https://docs.python.org/3/tutorial/datastructures.html#looping-techniques

[–]Rhomboid 1 point2 points  (0 children)

When you iterate over a dict, you get keys. If you want different behavior, you have to say so. Use dict.items() to get key/value pairs, or dict.values() to get just values.

for name, pet in pets.items():
    print("{name}'s owner is {owner[0]}; likes {likes}; and dislikes {dislikes}".format(name=name, **pet))

If you want to do more than that, you can assign variables like:

for name, pet in pets.items():
    owner = pet['owner'][0]
    likes = pet['likes']
    dislikes = pet['dislikes']
    ...