Python ValueError: dictionary update sequence element #0 has length 5; 2 is required

preview_player
Показать описание
ValueError: dictionary update sequence element #0 has length 5; 2 is required
d = {}

d
{1: 1, 2: 2}

l = ["hello", "hi"]

Traceback (most recent call last):
File "stdin", line 1, in module
ValueError: dictionary update sequence element #0 has length 5; 2 is required
Рекомендации по теме
Комментарии
Автор

It's expecting a KEY and VALUE separated by COLON, hence length of 2
The solution to this is just to pass in key value pair NOT a string, tuple, list, etc.
Ex:


for key, value in orig_dict.items():
new_dict.update({key:value})


or


x = {key:value}


new_dict.update(x)


or


new_dict.update({key:value})

PumaTomb