Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

'ValueError: too many values to unpack (expected 10)'

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading