A simplification of my dictionary:
my_dict = {
'DOC': [
[('k', 'v'), ('k1', 'v1'), ('k2', 'v2'), ('k3', 'v3'), ('k4', 'v4')],
[('k5', 'v5'), ('k', 'v'), ('k1', 'v1'), ('k6', 'v6')]
],
'DIC': [
[('k7', 'v7'), ('k3', 'v3'), ('k8', 'v8')],
[('k5', 'v5'), ('k3', 'v3'), ('k1', 'v1'), ('k2', 'v2')],
[('k4', 'v4'), ('k9', 'v9')]
],
'INFRA': [
[('k5', 'v5'), ('k3', 'v3'), ('k1', 'v1'), ('k2', 'v2')],
[('k', 'v'), ('k1', 'v1'), ('k2', 'v2'), ('k3', 'v3'), ('k4', 'v4')]
]
}
Overwriting my dictionary values:
for k, v in my_dict.items():
my_dict[k] = map(lambda x: dict(x), my_dict[k])
Returning…
my_dict
{'DIC': [{'k3': 'v3', 'k7': 'v7', 'k8': 'v8'},
{'k1': 'v1', 'k2': 'v2', 'k3': 'v3', 'k5': 'v5'},
{'k4': 'v4', 'k9': 'v9'}],
'DOC': [{'k': 'v', 'k1': 'v1', 'k2': 'v2', 'k3': 'v3', 'k4': 'v4'},
{'k': 'v', 'k1': 'v1', 'k5': 'v5', 'k6': 'v6'}],
'INFRA': [{'k1': 'v1', 'k2': 'v2', 'k3': 'v3', 'k5': 'v5'},
{'k': 'v', 'k1': 'v1', 'k2': 'v2', 'k3': 'v3', 'k4': 'v4'}]}
When I ran my real code following the same logic I got the error:
ValueError: dictionary update sequence element #0 has length 6; 2 is required
I’ve tried to create another dictionary to receive the map() but the same error occurred. Someone could help me?
The
dictconstructor expects a sequence of 2 item subsequences (lists or tuples). At least one of subsequences contains more then two items.Perhaps you have missing comma (see last item):
Or maybe a single item instead of a tuple (again, see last item)