Even totals from a mixed order list
Python data engineering interview problem. Difficulty: beginner. Pattern: Sorting. About 10 minutes. Free to practice.
A payments file mixes even and odd integer totals because of a legacy cents encoding. A recon job should keep only the even totals for one ledger.
An order list mixes totals, and finance only wants the even ones. Return a new list with only the even numbers, in the same order as the input. Write even_totals(totals). From [1, 2, 3, 4], the even totals are [2, 4]. An empty list gives []. The starter file already has the function name and its print lines. Keep them and fill in the body.
Requirements
- Keep only values that are divisible by 2.
- Keep the original order.
- Return [] for an empty list.
Constraints
- totals is a list of whole numbers.
- Zero is even.
Examples
Input: even_totals([1, 2, 3, 4]) Output: [2, 4] This input follows the stated rules and produces this output.
Topics: lakebench, python, comprehensions.
More Python interview questions · All interview problems · Learn data engineering
Even totals from a mixed order list
Interview-style drill: Return the order totals that are even numbers, using a single expression.
Return the even numbers from a mixed list of order totals.