Keep the evens · Giữ lại các số chẵn
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.
Giữ lại các số chẵn
Lọc một danh sách: giữ lại một số phần tử và loại bỏ những phần còn lại.
Bắt đầu với một danh sách rỗng, duyệt qua nums, và thêm vào .append() mỗi số thỏa mãn điều kiện kiểm tra n % 2 == 0. Trả về danh sách mới sau khi vòng lặp hoàn tất.
Write evens(nums) that returns a new list holding only the even numbers from nums, in the same order. · Viết evens(nums) trả về một danh sách mới chỉ chứa các số chẵn từ nums, giữ nguyên thứ tự.
Click Run to see the output here. · Nhấn Chạy để xem kết quả ở đây.