Skip to content
Advertisement

How to access a multiple dictionary in python?

I have a following dictionary:

JavaScript

Lets suppose I would like to print a value using print(pokus[1]["ahoj"][0]["visit"][0]). But I nedd [1]["ahoj"][0]["visit"][0] to be in an extra variable. I try this:

JavaScript

But I get an error TypeError: list indices must be integers or slices, not str . Is there a way how to do that in Python? Thanks

Advertisement

Answer

You cannot do this with an extra variable alone, you need to use a function, e.g.:

JavaScript

With variables from your question:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement