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?
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']
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.