python max value code example
Example 1: max int value in python
import sys
MAX_INT = sys.maxsize
print(MAX_INT)
''' NOTE: value of sys.maxsize is depend on the fact that how much bit a machine is. '''
Example 2: python max function
square = {2: 4, -3: 9, -1: 1, -2: 4}
key1 = max(square)
print("The largest key:", key1)
key2 = max(square, key = lambda k: square[k])
print("The key with the largest value:", key2)
print("The largest value:", square[key2])
Example 3: max value in python
print(max("abcDEF"))
print(max([2, 1, 4, 3]))
print(max(("one", "two", "three")))
'two'
print(max({1: "one", 2: "two", 3: "three"}))
3
print(max([], default=0))
Example 4: how to get maximum value of number in python
float('inf')
Example 5: python max()
i = max(2, 4, 6, 3)
print(i)
Example 6: python max with custom function
nums = [1,2,3,1,1,3,3,4,4,3,5]
counts = collections.Counter(nums)
return max(counts.keys(), key=counts.get)