DEV Community

Cover image for Bug of the week #6
pikoTutorial
pikoTutorial

Posted on • Originally published at pikotutorial.com

Bug of the week #6

Welcome to the next pikoTutorial !

The error we're handling today is a Python runtime error:

ValueError: too many values to unpack
Enter fullscreen mode Exit fullscreen mode

What does it mean?

The "too many values to unpack" error typically occurs when there is a mismatch between the number of variables or elements being unpacked and the number of values being assigned. This situation commonly arises in unpacking sequences like tuples or lists during assignment operations.

How to fix it?

Let's look at the following code:

a, b = [1, 2, 3]
Enter fullscreen mode Exit fullscreen mode

In this example a list from which we're taking values has 3 elements, but we've provided only to variables to store them (a and b), so the value 3 has no place to go. To fix this, either add an additional variable or reduce the number of elements in the list.

a, b, c = [1, 2, 3]
Enter fullscreen mode Exit fullscreen mode
a, b = [1, 2]
Enter fullscreen mode Exit fullscreen mode

Top comments (0)