names = 'area brand question price'.split()
lst = [{name:value for name, value in zip(names, t)} for t in tlst]
Test:
tlst = [('a1','b1','q1','p1'),
('a2','b2','q2','p2'),
('a3','b3','q3','p3')]
names = 'area brand question price'.split()
lst = [{name:value for name, value in zip(names, t)} for t in tlst]
print(lst)
@dokelung’s method can be more concise
Test:
Result:
Questions I answered: Python-QA
Simple way of writing: (a is an array of tuples)
Of course you can also try the mapping method, which is not covered here
In order to forcefully show off, use $lambda$ expression to write:
Please ignore my answer. . .
The correct solution upstairs is to form a separate dictionary, and then call the append of the array and it will be ok