'Print list item in python

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?



Solution 1:[1]

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']

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 BrokenBenchmark