Skip to content
Advertisement

indexing nested dictionary elements

I am trying to access the dictionary elements in python, which looks like this:

mydict= {'message':'','result':[{'abc':1,'xyz':2}]} 

I want to access the value of key 'xyz'.Is there any direct method to access it in python.

Any help is greatly appreciated.

Advertisement

Answer

In steps,

  • mydict['result'] returns [{'abc':1,'xyz':2}]
  • mydict['result'][0] returns {'abc':1,'xyz':2}
  • mydict['result'][0]['xyz'] returns 2
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement