find the max of a data set in python

You can use the max() function to find the maximum value in a data set. This function accepts an iterable as an argument, such as a list or tuple, and returns the largest item in the sequence.

Here's an example:

main.py
data_set = [3, 7, 2, 11, 4, 6]
max_value = max(data_set)
print(max_value)
74 chars
4 lines

This will output:

main.py
11
3 chars
2 lines

If your data set contains non-numeric values, you can pass a key function as a second argument to the max() function. For example, to find the longest string in a list of strings, you could use:

main.py
data_set = ['apple', 'banana', 'cherry', 'date']
max_value = max(data_set, key=len)
print(max_value)
101 chars
4 lines

This will output:

main.py
banana
7 chars
2 lines

related categories

gistlibby LogSnag