![](/img/trans.png)
[英]Why does my len() code in python not provide the correct length of a string?
[英]Why does python not provide output in this code?
def prepareData(dataset):
X,y=[],[]
for words in dataset:
X.append([features(untag(dataset), s) for s in range(len(dataset))])
y.append([tag for word,tag in sentences])
return X,y
ValueError: too many values to unpack (expected 2)
這里, dataset
是一個列表, s
是列表中任何 object 的 integer 值索引。
問題在於這一行:
y.append([tag for word,tag in sentences])
你沒有告訴我們sentences
是什么,但很明顯它不是它需要的。
例如:
sentences = ['this is a test','a quick brown fox']
[tag for word,tag in sentences]
ValueError: too many values to unpack (expected 2)
如果您的sentences
是兩個元組的列表,則代碼將起作用:
sentences = [('this is a test','tag1'),('a quick brown fox','tag2')]
In [15]: [tag for word,tag in sentences]
Out[15]: ['tag1', 'tag2']
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.