[Solved] Add to list in python if list is value in dictionary [closed]


This will do what you want:

In [2]: user_data["watched"].append(movie)

In [3]: user_data
Out[3]: {'watched': [{'title': 'Title A', 'genre': 'Horror', 'rating': 3.5}]}

Note that accessing a dictionary returns the value associated with the given key, so user_data["watched"] gives us the list object associated with that key "watched". Since we have a list, we can use the .append() method to add the movie dictionary to the list.

1

solved Add to list in python if list is value in dictionary [closed]