2024-06-02 08:16:31 发布
网友
我有一个字符串('3% Spandex,60% Polyester,7% Cotton,30% Other'),我想提取最高的值,在本例中是60% Polyester 因此,我认为如果我将字符串拆分成一个列表,然后去掉所有数值,这将使我能够找到最大值的位置,并使用它找到最大值。 但这是一个漫长的过程,我想这会让我慢下来。还有别的办法吗
('3% Spandex,60% Polyester,7% Cotton,30% Other')
60% Polyester
以下方面应起作用:
res=' '.join(max([i.split() for i in s.split(',')], key=lambda x:int(x[0].split('%')[0]))) >>> print(res) '60% Polyester'
以下方面应起作用:
相关问题 更多 >
编程相关推荐