EasyPython

List Comprehension — Squares Filter

PythonListsFunctional

Given a list of integers, return a new list containing the square of each number that is strictly positive, using a single list comprehension.

Examples

  • solve([1, -2, 3, 0, -4, 5])[1, 9, 25]
  • solve([-1, -2, -3])[]
  • solve([2, 4, 6])[4, 16, 36]

Constraints

  • Return an empty list if no positive number is found.
  • Do not mutate the input.
  • Your implementation must use a list comprehension (single expression, no for loop body).

Sample tests

Test #1Mixed positive, negative and zero
Input: [[1,-2,3,0,-4,5]]
Output: [1,9,25]
Test #2All negative — empty result
Input: [[-1,-2,-3]]
Output: []
Test #3All positive
Input: [[2,4,6]]
Output: [4,16,36]
Test #4Empty input
Input: [[]]
Output: []