# coding=utf-8
result = [
{"type": "MYSQL", "host": "going", "count": "100"},
{"type": "MYSQL", "host": "success", "count": "200"},
{"type": "MYSQL", "host": "failed", "count": "300"},
{"type": "redis", "host": "going", "count": "400"},
{"type": "redis", "host": "success", "count": "500"},
{"type": "redis", "host": "failed", "count": "600"},
]
def make_data(result):
ret = []
type_list = []
for t in result:
type = t.get("type")
if type not in type_list:
type_list.append(type)
print '\n'
print "type_list = ", type_list
for i in type_list:
a = dict()
for t in result:
if t.get("type") == i:
a.update({t.get('host'): t.get('count')})
a.update({"type": i})
print 'a = ', a
ret.append(a)
return ret
if __name__ == "__main__":
# print "ret = ", ret
ret = make_data(result)
print 'ret_finally = ', ret