Nikita Belooussov Nikita Belooussov - 4 months ago 23
Python Question

OrderedDict too many values to unpack

My program is producing:


ValueError: too many values to unpack.


I copied the lines of code that works in other instances.

new_dict = (("data", 0))
new_dict = collections.OrderedDict(new_dict) #the line producing the error


The only difference between this and the other ones that seem to work is that they have more values.

Answer
new_dict = (("data", 0))

This is supposed to be a tuple containing key-value pairs. To create a tuple with just one element, add a trailing comma.

new_dict = (("data", 0),)
Comments