简体   繁体   English

python 中打印列表项

[英]Print list item in python

I use the pipeline in python to translate reviews into the English language using this instruction我使用 python 中的管道使用此指令将评论翻译成英语

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

And the result was a list:结果是一个列表:

[{'translation_text': '“Excellent”. [{'translation_text': '“优秀”。 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'] :您可以索引列表和字典——使用[0]访问第一个元素,并使用['translation_text']访问字典的唯一值:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM