我有一个列表:
numbers = [1, 2, 3, 4, 5, 5, 2, 3]
现在我知道如何获得最大整数了:
max(numbers)
但这只会得到 5。我想要的是列表中的两个 5。有没有办法获取列表中所有最高的整数?
最佳答案
您可以使用 list comprehension :
max_num = max(numbers)
highest = [num for num in numbers if num == max_num]
关于python - 如何在 Python 中获取列表中的所有最高整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46758628/