打印出列表中最大数的第 n 个值 [重复]

Posted

技术标签:

【中文标题】打印出列表中最大数的第 n 个值 [重复]【英文标题】:Printing out the nth value of the max number within a list [duplicate] 【发布时间】:2021-03-30 20:04:36 【问题描述】:

我想打印出列表中最大数的第 n 个值

list_= [1,3,2,2,8,11,4]
max_val = max(list_)

预期输出

The maximum value of 11 is at the 6th place from the start of the order

【问题讨论】:

查看index 方法。 list_.index(max(list_)) index => list_.index(max(list_)) + 1th place. 这能回答你的问题吗? Pythonic way to find maximum value and its index in a list? index 不必要地循环列表两次。请参阅链接帖子上的答案以获得更快的答案。 @Aplet123 @Escualo 在给定链接中的回答似乎表明index 的显式使用即使不是更快也一样快。 【参考方案1】:

获取列表中最大值的索引

list_.index(max(list_))

【讨论】:

以上是关于打印出列表中最大数的第 n 个值 [重复]的主要内容,如果未能解决你的问题,请参考以下文章