solutions

Square elements using list comprehensions

Write a function that receives a list of integers and returns a list with all the elements squared using list comprehensions.

square_elements([1, 2, 3, 4, 5]) == [1, 4, 9, 16, 25]

Test Cases

test square elements repeated - Run Test

def test_square_elements_repeated():
    square_elements([1, 1, 2, 2, 3, 3]) == [1, 1, 4, 4, 9, 9]

test square elements empty list - Run Test

def test_square_elements_empty_list():
    square_elements([]) == []

test square elements - Run Test

def test_square_elements():
    square_elements([1, 2, 3, 4, 5]) == [1, 4, 9, 16, 25]