排序函数(列表/元组)反向错误工作

2024-06-14 19:41:59 发布

您现在位置:Python中文网/ 问答频道 /正文

fn = sorted(finalDataSet,key = lambda x : x[1],reverse=True)

我得到了这样的结果:

[('Hyperelastic', '8%'), ('Orthotropic', '26%'), ('Plastic', '23%'),
 ('Composites', '17%'), ('Anisotropic', '13%'), ('Thermal', '13%')]

Tags: lambdakeytruereversefnsortedthermalcomposites
1条回答
网友
1楼 · 发布于 2024-06-14 19:41:59

它似乎工作正常。按字符串排序,按字母顺序,“8%”被认为大于“26%”。您可能会发现这更有用,因为您的lambda

lambda x : float(x[1].strip('%'))

相关问题 更多 >