I have a list like this:
list = [{'a': 1}, {'b': 2}, {'c': 3}]
i want to convert that list to dict like this:
dict = {'a': 1, 'b': 2, 'c': 3}
anyone can help me ?
I have a list like this:
list = [{'a': 1}, {'b': 2}, {'c': 3}]
i want to convert that list to dict like this:
dict = {'a': 1, 'b': 2, 'c': 3}
anyone can help me ?
lst = [{'a': 1}, {'b': 2}, {'c': 3}]
result = {}
for elm in let:
for i,value in elm.items():
dictionary[i] = value
print(results)
Use a nested loop to flatten the list of dicts, then use the dict
constructor.
l = [{'a': 1}, {'b': 2}, {'c': 3}]
result = dict(i for d in l for i in d.items())
It's also possible to "merge" these dicts into one in place:
l = [{'a': 1}, {'b': 2}, {'c': 3}]
result = l[0]
for d in l[1:]:
result.update(d)