Filtering in a list comprehension

In some cases, we would like to process only specific elements. For instance, we would like to take only strings that have lengths greater than 5 and make them uppercase. To filter only the strings that have lengths greater than 5, we can do that in list comprehension using an if condition:
locations = ['Maldives', 'Bali', 'Thailand', 'Egypt']
upper = [place.upper() for place in locations if len(place) > 5]
print(upper)
# ['MALDIVES', 'THAILAND']
This way we only took the places with lengths greater than 5 and created a new list upper with place.upper() elements.

Challenge

Given several numbers on a single line, you are asked to calculate the cube of the even ones and ignore the rest.
The input contains a single line with several integers separated by a space.
The program should output the cubes of the even numbers from the input.
Input
Output
2 3 9 4 0
8 64 0
 

Constraints

Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue