I am really struggling to get to grips with python and figuring out how to answer the following question:
1) Accept the movies list and a category name. If the category is not in the data, prints a message that says it does not exist and returns None.
This is list it's looking at:
movies = [
{
"name": "Usual Suspects",
"imdb": 7.0,
"category": "Thriller"
},
{
"name": "Hitman",
"imdb": 6.3,
"category": "Action"
},
{
"name": "Dark Knight",
"imdb": 9.0,
"category": "Adventure"
},
{
"name": "The Help",
"imdb": 8.0,
"category": "Drama"
},
{
"name": "The Choice",
"imdb": 6.2,
"category": "Romance"
},
{
"name": "Colonia",
"imdb": 7.4,
"category": "Romance"
},
{
"name": "Love",
"imdb": 6.0,
"category": "Romance"
}
]
And this is the code I have so far but it only returns the matches and prints for each non-match which is not what I want:
def incat(cat):
for m in movies:
if m['category'] == cat:
print(m['name'])
else:
print(cat + ' does not exist')
incat('Romance')
I'm probably really missing something very easy but am just finding it super tough to wrap my head around. Any help is really appreciated.