我正在尝试循环列表,但无法将其添加到 python 中的字符串
I'm trying to loop a list and unable to add it to the string in python
例如,我有如下代码,其中
res = get_prediction_eos(input_text)
print("res is : ", res)
answer = []
print("res ", res['bert'].split("\n"))
for i in res['bert'].split("\n"):
answer.append(i)
answer_as_string = " ".join(answer)
print("answer is : ", answer_as_string)
以上代码的输出返回如下:
res is : {'bert': 'up\nwrong\nhappening\nnew\nhappened'}
res ['up', 'wrong', 'happening', 'new', 'happened']
answer is : up wrong happening new happened
我确实有类似下面代码的文本:
text = "Hey what's"
主要需要的输出是'answer is : up wrong happening new happened'。我确实有一个像“嘿什么”这样的文本,我想将答案的输出添加到像
这样的文本中
Hey what's up
Hey what's wrong
Hey what's happening
Hey what's new
Hey what's happened
谁能帮我写代码?
您只需要遍历列表并打印文本 + 循环中的元素。
在 Python >= 3.6:
for e in res['bert'].split('\n'):
print(f'{text} {e}?')
例如,我有如下代码,其中
res = get_prediction_eos(input_text)
print("res is : ", res)
answer = []
print("res ", res['bert'].split("\n"))
for i in res['bert'].split("\n"):
answer.append(i)
answer_as_string = " ".join(answer)
print("answer is : ", answer_as_string)
以上代码的输出返回如下:
res is : {'bert': 'up\nwrong\nhappening\nnew\nhappened'}
res ['up', 'wrong', 'happening', 'new', 'happened']
answer is : up wrong happening new happened
我确实有类似下面代码的文本:
text = "Hey what's"
主要需要的输出是'answer is : up wrong happening new happened'。我确实有一个像“嘿什么”这样的文本,我想将答案的输出添加到像
这样的文本中Hey what's up
Hey what's wrong
Hey what's happening
Hey what's new
Hey what's happened
谁能帮我写代码?
您只需要遍历列表并打印文本 + 循环中的元素。
在 Python >= 3.6:
for e in res['bert'].split('\n'):
print(f'{text} {e}?')