Min, Max, Sum and Average in One Pass

Easy ⏱ 8 min 84% acceptance ★★★★☆ 4.2
Write list_stats(numbers) that returns a dictionary with keys min, max, sum, and average (a float) describing numbers. Assume numbers has at least one element.

Examples

Example 1
Input
numbers = [4, 8, 2, 10]
Output
{'min': 2, 'max': 10, 'sum': 24, 'average': 6.0}
Explanation

Standard aggregate stats over the list.

Constraints

  • 1 <= len(numbers) <= 10^5

Topics

ListsAggregation

Companies

FlipkartZomato

Hints

Hint 1

Python's built-ins min(), max(), sum() and len() cover everything you need.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.