Print list item in python

Viewed 61

I use the pipeline in python to translate reviews into the English language using this instruction

translated = pipe(reviews['review'][0])

And the result was a list:

[{'translation_text': '“Excellent”. Cleanliness and helpful staff.'}]

I want only this part '“Excellent”. Cleanliness and helpful staff.' to be printed.

how can I do it?

1 Answers

You can index into the list and dictionary -- accessing the first element using [0], and accessing the sole value of the dictionary using ['translation_text']:

translated = pipe(reviews['review'][0])[0]['translation_text']
Related