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]
# ['MALDIVES', 'THAILAND']
This way we only took the places with lengths greater than 5 and created a new list upper with place.upper() elements.
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.