Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ValueError: not enough values to unpack (expected 3, got 2)

first time posting a question so go easy on me.

I found some code online that i am trying to implement myself though i keep coming across this error

ValueError: not enough values to unpack (expected 3, got 2)

the code is as follows:

for i,feats,label in enumerate(testfeats):
        refsets[label].add(i)
        observed = classifier.classify(feats)
        testsets[observed].add(i)

If you can help me out this would be great :)

like image 486
Nick Gollcher Avatar asked Apr 18 '17 12:04

Nick Gollcher


2 Answers

To add to timgeb's answer, the solution is to change the header of your for loop:

    for i, (feats, label) in enumerate(testfeats):
        ...

which is the same as:

    for i, itemValue in enumerate(testfeats):
        feats, label = itemValue
        ...
like image 81
L3viathan Avatar answered Oct 13 '22 04:10

L3viathan


enumerate gives your an iterator over (index, value) tuples which are always of length two.

You are trying to unpack each two-value tuple into three names (i, feats, label) which must fail because of the mismatch of values in the tuple and number of names you are trying to assign.

like image 41
timgeb Avatar answered Oct 13 '22 03:10

timgeb