我需要遍历两个句子列表(前提和假设),以获得前提和假设的元组。
到目前为止,我所做的是:
def examples (premises, hypotheses, labels):
labels = list(labels)
ls=[]
for pr, hy in zip(premises, hypotheses):
prs=tuple(pr, hy)
ls=ls.append(prs)
我需要在列表的元组中附加前提和假设对。我的代码有意义吗?
您的代码有一些可纠正的问题:1.您没有返回ls;2. .append方法使ls发生突变,因此您不应说ls = ls.append(); 3.当您通过zip对象迭代两个变量时,会自动获得一个元组,因此您不想将其强制转换为元组。最后,我不确定要对标签做什么。您的代码的正确版本是:
def examples (premises, hypotheses, labels):
labels = list(labels)
ls=[]
for pr, hy in zip(premises, hypotheses):
prs = pr, hy
ls.append(prs)
return ls
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句