【问题标题】:Printing out the nth value of the max number within a list [duplicate]打印出列表中最大数的第 n 个值 [重复]
【发布时间】: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.
  • index 不必要地循环列表两次。请参阅链接帖子上的答案以获得更快的答案。
  • @Aplet123 @Escualo 在给定链接中的回答似乎表明index 的显式使用即使不是更快也一样快。

标签: python python-3.x list max


【解决方案1】:

获取列表中最大值的索引

list_.index(max(list_))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-10
    • 2013-08-05
    • 1970-01-01
    • 2020-02-14
    • 2014-01-12
    相关资源
    最近更新 更多