[Solved] Nested dictionaries

How can I access the keys inside of a dictionary?

For example:

 films = {'Finding Dory':{'age':15, 'ticket':5}}

And I would like to check if there are enough tickets

  if numberOfTickets > 0:
         any action here...

Hello tehuan.

Depending on how consistent your object is:

for key in films:
  if films[key]['ticket'] > 0:
    # Do something

I would add in a check to make sure that 'ticket' is in films.

I hope this helps

@Sky020 Thank you so much for your help!
I’m sorry about my questions, I’m totally beginner.
I understood how to access the key as the example below.

films = {'Finding Dory':{'age':15, 'ticket':5}}

if films['Finding Dory']['ticket'] > 0:
    print('Working fine')

But now Im a bit confuse about how to check if the key ‘ticket’ is in films. Can you show me please using a if statment?

Since films is a nested object, you will not be able to check to if a “ticket” is a key in films with a simple if statement. Your films dictionary only has one key (“Finding Dory”), but if all the the keys were film titles, then you would just need to add an extra check in the existing if statement to make sure ‘ticket’ exists in films[key]. Think about how you could use the in key word here to accomplish that.