Skip to content
Advertisement

How to access dictionary values

I am trying to print dictionaries keys and values separately, the dictionary that’ve created consist of 2 values in a list: {‘item’:[val1,val2]}

How can i access the values separately?

This is my code where i tried to access the value of val1, but am getting both of val1 & val2

JavaScript

Advertisement

Answer

This was answered here: How to access nested dictionary in python

Only instead of the second key you put the index

This kind of things are called nested dictionaries/lists To call them, here is the syntax:

JavaScript

To get a list of dictionary keys, go here: How to return dictionary keys as a list in Python?

To get a value from a key, do dictionary_name[key_name]

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