0Pricing
Competitive Programming Academy · Lesson

Build Arrays Fast with Comprehensions

Read and shape input in one line.

Build Lists in One Line

A list comprehension builds a list from a loop in a single expression. It is shorter, faster, and the contest standard for shaping data.

squares = [i * i for i in range(5)]

The Basic Shape

The pattern is [expr for item in iterable]. The expression on the left runs once for each item the loop yields.

doubles = [x * 2 for x in nums]

All lessons in this course

  1. Lists, Indexing & Slicing for CP
  2. Build Arrays Fast with Comprehensions
  3. Min, Max, Sum & Running Totals
  4. Find the Index, Not Just the Value
← Back to Competitive Programming Academy