Reviewed by Aditya Kumar Β· Last reviewed 2026-03-24
**Simple Filter:** [n for n in nums if n % 2 == 0]. Or filter(lambda n: n%2==0, nums). For print: for n in nums: if n%2==0: print(n). **Edge Cases:** Floats (n%2 works for int); NaN (use pd.notna). For Pandas: df[df['col'] % 2 == 0]....
Simple Filter: [n for n in nums if n % 2 == 0]. Or filter(lambda n: n%2==0, nums). For print: for n in nums: if n%2==0: print(n).
Edge Cases: Floats (n%2 works for int); NaN (use pd.notna). For Pandas: df[df['col'] % 2 == 0].
evens = [n for n in numbers if n % 2 == 0]
for n in evens: print(n)
Red Flag: Modifying list while iterating. Pro-Move: 'For float columns we use (df["col"] % 2).abs() < 1e-9 to handle precision.'
According to DataEngPrep.tech, this is one of the most frequently asked Python/Coding interview questions, reported at 1 company. DataEngPrep.tech maintains an editor-reviewed database of 1,863 data engineering interview questions across 7 categories.