An if at the end and an if-else at the front
Predict the output · Basic · §10.3 Filtering and choosing
These two comprehensions do the same calculation and differ only in where the condition goes. Predict the output without running the code.
Code
views = [40, 150, 90, 300]
tens = [v // 10 for v in views if v >= 100]
marks = [v // 10 if v >= 100 else 0 for v in views]
print(tens)
print(marks)Solve this problem in your browser
Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.