I would like to access the value of the following :
a = [{'translation_text': 'I love cake.'}]
Desired output:
"I love cake."
I tried the following:
a['translation_text']
and I get the following error:
TypeError: string indices must be integers
Has anyone experienced the same issue before? Thanks a lot for your help!
>Solution :
The dictionary is the first item of the list a, i.e., you need to access it by using its index, 0:
>>> a = [{'translation_text': 'I love cake.'}]
>>> a[0]
{'translation_text': 'I love cake.'}
>>> a[0]['translation_text']
'I love cake.'