Keep the evens · שמור את הזוגיים
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, והוסף (.append()) כל מספר שעובר את הבדיקה n % 2 == 0. החזר את הרשימה החדשה לאחר סיום הלולאה.
Write evens(nums) that returns a new list holding only the even numbers from nums, in the same order. · כתוב פונקציה evens(nums) שמחזירה רשימה חדשה המכילה רק את המספרים הזוגיים מ-nums, באותו סדר.
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.