a = {"k1":0,"k2":1,"k3":2}
大神我想把a字典变成 [{"k1":0},{"k2":1},{"k3":2}]
这个怎么整啊? 谢谢大神指点。
a = {"k1":0,"k2":1,"k3":2}
result = []
for k, v in a.items():
print(k, v)
result.append({k:v})
一行流
#一行流
result = [{k:v} for k,v in a.items()]
建议楼主再把python基础知识再过一遍,多练习。