[英]Convert tuples to a dictionaries
for the list of tuples below: 对于下面的元组列表:
[('a',1),('b', 2)]
I want to convert it to: 我想将其转换为:
[{'a' : 1}, {'b', 2}]
which is a list of dictionaries 这是词典列表
lst = [{k: v} for k, v in lst]
其中lst
是您的元组列表。
[{t[0] : t[1]} for t in [('a',1),('b', 2)]]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.