Skip to main content
  • Python is available now. All other compilers are coming soon.

    Python
  • Popular Tutorials

    • Getting Started With Python
    • Python if Statement
    • while Loop in Python
    • Python Lists
    • Dictionaries in Python
    All Python Tutorials

    Reference Materials

    Built-in FunctionsList MethodsDictionary MethodsString Methods
    View all

Online Compilers

  • Python Compiler
  • Python Playground
  • Python Projects
  • Exercises

Tutorials

  • Learn Python
  • Python for Beginners
  • Variables and Types
  • Python Strings
  • Python Lists
  • Python If Else
  • Python For Loops
  • Python Functions
  • Python Classes

Examples

  • Python Examples
  • Hello World
  • Add Two Numbers
  • Even or Odd
  • Factorial
  • Fibonacci
  • Prime Check
  • Palindrome Check

Company

  • About
  • Contact
  • Privacy Policy
  • Terms of Use
  • Disclaimer

© 2026 ILoveCompiler. All rights reserved.

  1. Home
  2. Python Examples
  3. List Statistics

Lists · Python example

List Statistics

Compute count, sum, minimum, maximum, and average for a list of numbers.

Open the compilerAll examples
beginnerlistsstatisticsbuilt-in functions

Lists are ordered collections with efficient built-in operations. This example uses len(), sum(), min(), and max() on one list.

example.py
numbers = [12, 7, 19, 4, 15]

count = len(numbers)
total = sum(numbers)
minimum = min(numbers)
maximum = max(numbers)
average = total / count

print(f"Count: {count}")
print(f"Sum: {total}")
print(f"Min: {minimum}")
print(f"Max: {maximum}")
print(f"Average: {average:.2f}")

How the code works

  • The five numbers are stored in a list.
  • The aggregate values are computed once and saved in variables.
  • The average is formatted to two decimal places.

Key ideas

  • len(numbers) returns the number of items.
  • sum() adds all numeric values.
  • min() and max() compare the values.

Try changing it

  • Compute the median with statistics.median().
  • Use a list comprehension to filter values above the average.
  • Read the numbers from a line of input.

Related examples

intermediate

Remove Duplicates while Preserving Order

Use dictionary keys to deduplicate a list without losing the original order.

beginner

Set Operations

Compare two skill sets with union, intersection, and difference.

Previous exampleCapitalize Each WordNext exampleRemove Duplicates while Preserving Order

Expected output

Count: 5
Sum: 57
Min: 4
Max: 19
Average: 11.40

Output is compared after trimming trailing whitespace on each line. Run the code to see it produced by CPython in your browser.

Practice next

Apply the same idea with automatic tests or browse a guided project.

ExercisesProjects