How do I create a list and only extract or search out the even numbers in that list?
Create a function even_only(l) that takes a list of integers as its only argument. The
function will return a new list containing all (and only) the elements of l which are evenly divisible by 2. The original list l shall remain unchanged.
For examples, even_only([1, 3, 6, 10, 15, 21, 28]) should return [6, 10, 28], and
even_only([1, 4, 9, 16, 25]) should return [4, 16].
Hint: Start by creating an empty list, and whenever you encounter an even number in it, add it to your list, then at the end, return your list.
“By hand”:
Pythonic:
Since it’s homework, you can fill in the
is_evenfunction.