Junior Codes
Inventor Studio

Python List Comprehensions for Kids

Build a whole new list in a single, readable line.

Start Wonderwild free with Pip

Try 5 starter activities free. Full access is ₹499 a year.

This mission is part of full access. The first missions are free to try.

List comprehensions, explained simply

Often you make a new list by looping over another list and appending something each time. A list comprehension does all of that in one line.

Read [n * 2 for n in numbers] as "n times two, for every n in numbers". The square brackets tell Python the result is a list.

You can add an if at the end to keep only some items: [n for n in numbers if n > 3]. Comprehensions are neat, but a normal loop is fine when the logic gets complicated.

Example: Make patterns quickly

sizes = [1, 2, 3, 4]
rows = ["*" * s for s in sizes]
print(rows)
print([s for s in sizes if s % 2 == 0])

Output

['*', '**', '***', '****']
[2, 4]

Try this

  • Make a list of the squares of the numbers 1 to 10.
  • Turn a list of names into capital letters with .upper() in a comprehension.
  • Write the same thing as a normal for loop and compare the two.

Practise it in Wonderwild

“Design a pattern collection”

Mission 30 in Inventor Studio, one of 36 Python missions in Wonderwild.

Your child writes and runs real Python in the browser while Pip reacts to every line. Nothing to install. For ages 7+.

Start Wonderwild free with Pip

Try 5 starter activities free. Full access is ₹499 a year.

This mission is part of full access. The first missions are free to try.

Questions parents and kids ask

Are list comprehensions faster than loops?+

Often slightly, but the real benefit is readability for simple transformations. Choose whichever is clearer for the job.

What does % mean in the example?+

It gives the remainder after dividing. s % 2 == 0 is True when s is even.

Prefer learning with a teacher?

Our live Python for Young Developers course teaches these ideas in small online classes led by a software engineer, with projects and feedback. Every live course also includes 12 months of full Wonderwild access for practice.

See the Python for Young Developers course