Error extracting dictionary items in zip method inside a for loop

33 Views Asked by At

I am trying to extract four variables in a for loop using zip method().

for actual,pred,key,val in zip(actual,pred,dict.items()):

But I am getting an error saying that the zip returns only 3 values instead of four.

not enough values to unpack (expected 4, got 3)

What is wrong here ?

1

There are 1 best solutions below

0
SIGHUP On

You pass 3 iterates to zip(). Therefore it will return 3 values. The value returned from _dict.items() will be a key/value tuple.

Here are two options:

for actual, pred, (key,val) in zip(actual, pred, _dict.items()):


for actual, pred, t in zip(actual, pred, _dict.items()):
    key, val = t