Python3 字典中混合list排序

mydict = {
	'Li':['M',7],
	'Zhang':['E',2],
	'Wang':['P',3],
	'Du':['C',2],
	'Ma':['C',9],
	'Zhe':['H',7]
}


res = sorted(mydict.items(),key=lambda x:x[1][1])#根据value结构[m,n]中n的值进行排序

print(res)

#输出
#[('Zhang', ['E', 2]), ('Du', ['C', 2]), ('Wang', ['P', 3]), ('Li', ['M', 7]), ('Zhe', ['H', 7]), ('Ma', ['C', 9])]

你可能感兴趣的:(python)