Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What does the max() function do in Python?
The max() function returns the largest item from an iterable or the largest of two or more arguments.
Click to reveal answer
beginner
What does the min() function do in Python?
The min() function returns the smallest item from an iterable or the smallest of two or more arguments.
Click to reveal answer
beginner
How can you find the maximum number in a list [3, 7, 2, 9]?
Use max([3, 7, 2, 9]) which will return 9.
Click to reveal answer
beginner
How can you find the minimum value among numbers 5, 10, and 1?
Use min(5, 10, 1) which will return 1.
Click to reveal answer
intermediate
Can max() and min() be used with strings? How?
Yes! They compare strings alphabetically (based on Unicode). For example, max(['apple', 'banana', 'cherry']) returns 'cherry' because 'c' comes after 'a' and 'b'.
Click to reveal answer
What will max([4, 9, 1, 7]) return?
A4
B7
C9
D1
✗ Incorrect
max() returns the largest number, which is 9.
What does min('dog', 'cat', 'bat') return?
A'bat'
B'cat'
C'dog'
DError
✗ Incorrect
Strings are compared alphabetically. 'bat' comes before 'cat' and 'dog'.
Which of these is a valid way to use max()?
Amax(3, 5, 2)
BAll of the above
Cmax('a', 'z', 'm')
Dmax([3, 5, 2])
✗ Incorrect
All options are valid uses of max().
What will min([]) do?
ARaise a ValueError
BReturn None
CReturn 0
DReturn an empty list
✗ Incorrect
min() raises a ValueError if given an empty iterable.
How does max() decide which item is largest when given strings?
ABy string length
BRandomly
CBy number of vowels
DAlphabetically (Unicode order)
✗ Incorrect
max() compares strings alphabetically using Unicode order.
Explain how to use max() and min() with a list of numbers.
Think about finding the highest and lowest scores in a game.
You got /4 concepts.
Describe what happens if you use max() or min() on strings.
Think about dictionary order.
You got /4 concepts.
Practice
(1/5)
1. What does the max() function do in Python?
easy
A. Finds the largest item in a list or among values
B. Finds the smallest item in a list or among values
C. Sorts the list in ascending order
D. Removes duplicates from a list
Solution
Step 1: Understand the purpose of max()
The max() function is used to find the biggest or largest item from a list or multiple values.
Step 2: Compare with other options
Options A, C, and D describe different functions or actions, not what max() does.
Final Answer:
Finds the largest item in a list or among values -> Option A
Quick Check:
max() = largest item [OK]
Hint: max() returns the biggest value from inputs [OK]
Common Mistakes:
Confusing max() with min()
Thinking max() sorts the list
Assuming max() removes duplicates
2. Which of the following is the correct way to find the minimum value in a list named nums?
easy
A. minimum(nums)
B. min(nums)
C. nums.min()
D. min = nums
Solution
Step 1: Recall the syntax of min()
The correct syntax to find the smallest value in a list is min(list_name). So, min(nums) is correct.
Step 2: Check other options for errors
minimum(nums) uses a non-existent function minimum(). nums.min() tries to call min() as a method on the list, which is invalid. min = nums assigns min to the list, which is incorrect usage.
Final Answer:
min(nums) -> Option B
Quick Check:
min(list) = smallest value [OK]
Hint: Use min(list_name) to get smallest value [OK]
The largest value is 9 and the smallest value is 2.
Final Answer:
9 and 2 -> Option A
Quick Check:
max = 9, min = 2 [OK]
Hint: max() and min() find biggest and smallest values [OK]
Common Mistakes:
Mixing up max and min results
Assuming print shows the whole list
Syntax errors from missing parentheses
4. The following code gives an error. What is the problem?
values = [10, 20, 30]
print(max(values, key=abs))
medium
A. The key function abs() is unnecessary here
B. max() cannot be used with lists
C. The code runs without error and prints 30
D. abs() is not defined
Solution
Step 1: Understand max() with key parameter
The key parameter lets max() compare items by a function result. Here, abs returns absolute values, which are the same as the original values since all are positive.
Step 2: Check if code runs correctly
Since abs is a built-in function and the list is valid, the code runs without error and returns the largest value, 30.
Final Answer:
The code runs without error and prints 30 -> Option C
Quick Check:
max(values, key=abs) = 30 [OK]
Hint: max() with key=abs works fine; abs() is built-in [OK]
Common Mistakes:
Thinking abs() is undefined
Believing max() can't use key parameter
Assuming code causes error
5. Given the list words = ['apple', 'banana', 'grape', 'kiwi'], which code finds the word with the shortest length?
hard
A. max(words)
B. max(words, key=len)
C. min(words)
D. min(words, key=len)
Solution
Step 1: Understand the key parameter with len()
Using key=len tells min() to compare words by their length, not alphabetically.
Step 2: Identify shortest word
Among the words, 'kiwi' has the shortest length (4 letters). So min(words, key=len) returns 'kiwi'.
Final Answer:
min(words, key=len) -> Option D
Quick Check:
min by length = 'kiwi' [OK]
Hint: Use min(list, key=len) to find shortest string [OK]