As the other answers show, you can use dict() .
But as a curiosity, perhaps you can also use reduce
EDIT . As the comment says, dict() is easier in this case. But, just for the sake of theory, I had in mind what can be solved using only functional building blocks (without understanding the magic of the python dictionary):
def union(d1,d2): result = {} result.update(d1) result.update(d2) return result
Then:
reduce(union, sequence_of_dictionaries, {})
Alternatively, less clean but more efficient, using an alternative version of dict.update, which returns its first argument:
def update2(d1, d2): dict.update(d1, d2) return d1
Or even:
update2 = lambda d1,d2: (d1, d1.update(d2))[0]
Then:
reduce(update2, sequence_of_dictionaries, {})
Where in this case sequence_of_dictionaries will be:
[{'{t}.{c}'.format(t=h.table_name, c=h.column_name) : h.position} for h in self.heading_set.all()]
sinelaw
source share