Skip to content

Keep the evens · ⁨只留下偶数⁩

English

Keep the evens

Filter a list: keep some items and leave the rest out.

Start with an empty list, loop over nums, and .append() each number that passes the test n % 2 == 0. Return the new list after the loop has finished.

中文

只留下偶数

筛选列表:保留一部分元素,去掉其余的。

先建一个空列表,遍历 nums,把通过 n % 2 == 0 判断的数用 .append() 加进去。循环结束后返回这个新列表。

Log in or create account · ⁨登录或创建账户⁩

IGCSE, A-Level · ⁨IGCSE、A-Level⁩ & AP · ⁨与 AP⁩