Use Python’s built-in max() to find the largest item in a list or other iterable: max([3, 5, 9, 1]) returns 9. For dictionary values or records, pass a key function that tells Python what to compare.
Find the largest item in a list or iterable
Pass a single iterable—such as a list, tuple, or other sequence—to max():
numbers = [3, 5, 9, 1]
largest = max(numbers)
print(largest) # 9
Python’s built-in function returns the largest item in an iterable, or the largest of two or more arguments. See the official built-in functions documentation.
Choose the right call form
One positional argument is treated as an iterable. Two or more positional arguments are compared directly; they are not treated as one collection.
#1 Best Overall
max([3, 5, 9, 1]) # 9: one iterable
max(3, 5, 9, 1) # 9: several arguments
The documented forms are max(iterable, *, key=None), max(iterable, *, default, key=None), and max(arg1, arg2, *args, key=None). The default argument applies only to the single-iterable form and must be passed by keyword.
Handle an empty iterable
Calling max() on an empty iterable without a fallback raises ValueError. If emptiness is expected, provide a meaningful default:
Rank #2
largest = max([], default=0)
print(largest) # 0
Choose a fallback that cannot be mistaken for a real maximum in your application. For example, if zero is a valid value and you need to distinguish an empty input from a maximum of zero, use a separate sentinel or check for emptiness instead of returning zero.
The default parameter was added in Python 3.4. The official documentation also notes that allowing key=None was added in Python 3.8.
Find the longest word or rank items with key
Use key when you want to compare items by a derived property. The function receives each item and returns the value used for comparison; max() returns the original item, not the key result.
words = ["pear", "watermelon", "fig"]
longest = max(words, key=len)
print(longest) # watermelon
Here, Python compares word lengths but returns the matching word. The same pattern works for objects or records when you supply a function that extracts the attribute you want to rank.
Get the dictionary key with the largest value
Iterating over a dictionary visits its keys. To find the key whose mapped value is greatest, use the dictionary’s get method as the comparison key:
scores = {"Mina": 88, "Leo": 94, "Aria": 91}
top_scorer = max(scores, key=scores.get)
print(top_scorer) # Leo
This returns "Leo", the key—not the score. To retrieve both the key and value as a pair, compare the dictionary’s items by their second element:
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Best Value
top_entry = max(scores.items(), key=lambda item: item[1])
print(top_entry) # ('Leo', 94)
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Know how ties are resolved
If multiple items share the maximum comparison value, max() returns the first one encountered. For example, with equal scores, the first matching dictionary entry in iteration order wins. If your application needs a different tie-breaker, encode it in the key function or identify all tied items explicitly.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




