1square = {2: 4, -3: 9, -1: 1, -2: 4}
2
3# the largest key
4key1 = max(square)
5print("The largest key:", key1) # 2
6
7# the key whose value is the largest
8key2 = max(square, key = lambda k: square[k])
9
10print("The key with the largest value:", key2) # -3
11
12# getting the largest value
13print("The largest value:", square[key2]) # 9
14
1# find largest item in the string
2print(max("abcDEF"))
3
4# find largest item in the list
5print(max([2, 1, 4, 3]))
6
7# find largest item in the tuple
8print(max(("one", "two", "three")))
9'two'
10
11# find largest item in the dict
12print(max({1: "one", 2: "two", 3: "three"}))
133
14
15# empty iterable causes ValueError
16# print(max([]))
17
18# supressing the error with default value
19print(max([], default=0))
20
1i = max(2, 4, 6, 3)
2
3print(i)
4# Result will be 6 because it is the highest number
1print(max(2, 3)) # Returns 3 as 3 is the largest of the two values
2print(max(2, 3, 23)) # Returns 23 as 23 is the largest of all the values
3
4list1 = [1, 2, 4, 5, 54]
5print(max(list1)) # Returns 54 as 54 is the largest value in the list