map and filter
Completed
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]
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)))