Search code examples
pythonbiopythonncbi

Extracting a value from a combination of list of dictionaries


The eutils package form NCBI returns the below object for a specific request. From this I want to extract the value 245540. How can I do that?

[{u'LinkSetDb'       : [{u'DbTo'     : 'sra',
                         u'Link'     : [{u'Id': '245540'}], 
                         u'LinkName' : 'biosample_sra'}],
  u'DbFrom'          : 'biosample', 
  u'IdList'          : ['1178400'], 
  u'LinkSetDbHistory': [],
  u'ERROR'           : []}]

Solution

  • if the variable name is var then var[0]['LinkSetDb'][0]['Link'][0]['Id']