map and filter

Lab Python Intermediate 20 points

Read a line of integers. Using filter keep the positive ones, then using map square them. Print the result as a list.

Input

One line.

Output

The list.

Example

Input

-2 3 0 4 -1

Output

[9, 16]
Sample input available Sample output available
Editor
Python

Hints

filter(function, items) keeps items where the function returns True.

Both return lazy iterators - wrap in list() to print.

Solution explanation

map/filter are lazy; a comprehension is usually more readable, but you'll meet both styles.

Show solution
nums = map(int, input().split())
positives = filter(lambda x: x > 0, nums)
print(list(map(lambda x: x * x, positives)))
Output
Answer
HOME LEARN COMMUNITY DASHBOARD