Search code examples
pythondictionaryncbi

How do I print a specific string out of a dictionary element?


SOLVED: Its a a key in a dictionary embedded as an element in a list

print(read[0]["Title"])

Heres a picture of the output I am trying to print the article titles (end of line 2) from this esummary request. However, I am unfamiliar with dictionary lists.

I have tried splitting and slicing but those are for elements and strings. I have also looked at Accessing elements of Python dictionary by index to no avail. Here's some code...

titles = Entrez.esummary(db="Pubmed", id= "31106594, 30889179")

read = Entrez.read(titles)

print(read["Title"])

I want it to print "Development of a Molecularly Stable Gene Therapy Vector for the Treatment of RPGR-associated X-linked Retinitis Pigmentosa"

Instead it says "TypeError: list indices must be integers or slices, not str"


Solution

  • Its a a key in a dictionary embedded as an element in a list

    for i in range(len(read)):
        print(read[i]["Title"])