字典嵌套列表处理,求助
请问如何将report = {1:{'1-2':[1,2,3],'1-3':[2,3,4]},2:{'2-1':[3,4,5],'2-3':[4,5,6]},3:{'3-1':[3,4,6],'3-2':[5,8,4]}} 这样的数据,转换成report = {1:{'1-2':1,'1-3':2},2:{'2-1':3,'2-3':4},3:{'3-1':3,'3-2':5}}这样的数据,谢谢。
[解决办法]
report = {1:{'1-2':[1, 2, 3], '1-3':[2, 3, 4]}, 2:{'2-1':[3, 4, 5], '2-3':[4, 5, 6]}, 3:{'3-1':[3, 4, 6], '3-2':[5, 8, 4]}}
#print report
for key, subdict in report.items() :
#print key
for subkey, lst in subdict.items() :
#print '\t', subkey, lst
subdict[subkey] = lst[0]
print report