In [1]:
#Using min and max with a List of Integers
numbers = [4, 6, 1, 3, 9, 2]
print("Minimum:", min(numbers))
print("Maximum:", max(numbers))
Minimum: 1 Maximum: 9
In [2]:
#Using min and max with a List of Strings
words = ["apple", "banana", "cherry", "date"]
print("Minimum:", min(words))
print("Maximum:", max(words))
Minimum: apple Maximum: date
In [3]:
#Using min and max with a Dictionary
students = {
"Alice": 85,
"Bob": 92,
"Charlie": 78
}
print("Student with min score:", min(students, key=students.get))
print("Student with max score:", max(students, key=students.get))
Student with min score: Charlie Student with max score: Bob
In [4]:
#Using min and max with Healthcare Data
patients = [
{"name": "John", "age": 45, "blood_pressure": 120},
{"name": "Jane", "age": 50, "blood_pressure": 130},
{"name": "Doe", "age": 40, "blood_pressure": 110}
]
min_age_patient = min(patients, key=lambda x: x["age"])
max_age_patient = max(patients, key=lambda x: x["age"])
print("Patient with minimum age:", min_age_patient)
print("Patient with maximum age:", max_age_patient)
# Finding the patient with the minimum and maximum blood pressure
min_bp_patient = min(patients, key=lambda x: x["blood_pressure"])
max_bp_patient = max(patients, key=lambda x: x["blood_pressure"])
print("Patient with minimum blood pressure:", min_bp_patient)
print("Patient with maximum blood pressure:", max_bp_patient)
Patient with minimum age: {''''name'''': ''''Doe'''', ''''age'''': 40, ''''blood_pressure'''': 110} Patient with maximum age: {''''name'''': ''''Jane'''', ''''age'''': 50, ''''blood_pressure'''': 130} Patient with minimum blood pressure: {''''name'''': ''''Doe'''', ''''age'''': 40, ''''blood_pressure'''': 110} Patient with maximum blood pressure: {''''name'''': ''''Jane'''', ''''age'''': 50, ''''blood_pressure'''': 130}