How to find the max number(s) in a list with tied numbers

后端 未结 4 636
[愿得一人]
[愿得一人] 2020-12-06 06:07

So say I have a list like:

my_list = [12, 13, 51, 21, 22, 58, 45.1, 34.2, 56, 6, 58, 58] 

So the max number in this is obviously 58, but I

4条回答
  •  难免孤独
    2020-12-06 06:52

    Similar to enumerate and list comprehension, you can also use filter:

    maxval = max(my_list)
    indices = list(filter(lambda x: my_list[x]==maxval, list(range(len(my_list)))))
    

提交回复
热议问题