Skip to content
Advertisement

‘ValueError: too many values to unpack (expected 10)’ [closed]

I am working on a self-learning project on AIS ship tracking, and the following line of code:

hi_boat1,hi_boat2,hi_boat3,hi_boat4,hi_boat5,hi_boat6,hi_boat7,hi_boat8,hi_boat9,hi_boat10 = [x for _, x in hi_eez.groupby(hi_eez['mmsi'])]

is giving me the following error:

ValueError: too many values to unpack (expected 10)

What should I do?

Advertisement

Answer

the error says that the code on the right-hand side of the expression should return a list with 10 objects as you use ten variables on the left hand side for unpacking that list.

see “Too many values to unpack” Exception

e.g. a,b,c,d,e,f,g = [x for x in range(7)] works while a,b,c,d,e,f,g = [x for x in range(8)] throws ValueError: too many values to unpack (expected 7)

you should state what you are trying to achieve and maybe add the desired output. so, you could for example assign that list to a variable and then further process it.

my_list = [x for _, x in hi_eez.groupby(hi_eez['mmsi'])]

for elem in my_list:
    print(elem)
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement