dict1 = {1:2,3:4,6:7,9:10} print dict((v,k) for k,v in dict.items()) 结果 {2:1.4:3,10:9,7:6}
res = [{'id':1,'name':'wd','age':'18'},{'id':2,'name':'pc','age':'20'}] dict((str(x['id']),x['name'])for x in res)
{str(x["id"]):x['name'] for x in res} 结果 {'1':'wd','2':'pc'}