[英]How to find the highest value element in a list with reference to a dictionary on python
[英]How to find the highest Value with Python
我有一些变量值,它的变化就像
我得到这些值
a = 0
b = 2
c = 4
d = 0
print (c)
如何打印上面和下面的最高值
a = 6
b = 0
c = 5
d = 0
print (a)
请让我知道如何使用 python 获得最高价值
谢谢你
# Python program to find largest
# number in a list
# list of numbers
list1 = [10, 20, 4, 45, 99]
# printing the maximum element
print("Largest element is:", max(list1))
这个想法是将所有值分组在一个容器中,例如一个列表,这样您就可以将它们作为一个对象进行操作,即列表。 然后使用max
函数
values = [a, b, c, d]
print(max(values))
注意max
也直接接受多个值
print(max(a, b, c, d))
from functools import reduce
import heapq
arr = [10, 324, 45, 90, 9808,11]
# method 1
max_number = arr[0]
for ele in arr:
if ele > max_number:
max_number = ele
print("max number is", max_number)
# method 2
lis = [10, 324, 45, 90, 9808,11]
lis.sort(reverse=True)
print("max number is", lis[0])
#method 3
print("max number is", max(arr))
# method 4
max_num = reduce(max,arr)
print("max number is", max_num)
# method 5
max_num1 = reduce(lambda x,y:x if x>y else y,arr)
print("max number is", max_num)
# method 6
max_num2 = heapq.nlargest(1,arr)
print("max number is", max_num2)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.