Guidelines

Coding Quiz - Extract Elements from List

In this Python coding quiz, you'll write a function that extracts elements from a list based on a specific condition using the filter and map functions, then applies a transformation to each extracted element.

The function below, named solution, should take a list of integers as input, extract only the odd numbers, and return a new list with each extracted odd number multiplied by 2.

Function Parameter Format
def solution(numbers): # Write your code here return

Constraints

  • The input list consists of integers.

  • The output list should contain the result of multiplying each odd element from the input list by 2.


Example Input and Output

  • Input: [1, 2, 3, 4, 5]

  • Output: [2, 6, 10]

Mission
0 / 1

Extract and Transform Odd Numbers from a List

Extract only the odd numbers from a given list and create a new list by multiplying each odd number by 2. For example, if the input list is [1, 2, 3, 4, 5], the output should be [2, 6, 10].

numbers = [1, 2, 3, 4, 5]

result = list(map(lambda x: x * 2, filter(lambda x: x % 2 != 0, 
)))

print(result)

Guidelines

AI Tutor

Publish

Design

Upload

Notes

Favorites

Help