Evens first
Inputs
values is a list of 0 to 14 whole numbers, each from 0 to 40.
Your tasks
- Create two empty lists,
evensandodds. - Use a loop over
values. Put each number in the list it belongs to. - Join them,
evensfirst. - Complete
evensFirstso it returnsevensfollowed byodds. Return it, do not print it.
Example
With values = [5, 2, 8, 3, 6, 1], evensFirst returns [2, 8, 6, 5, 3, 1].
Rules
- Within each group, keep the original order.
Test data
TEST DATA 1: values is [5, 2, 8, 3, 6, 1]
TEST DATA 2: values is []
Practice focus
Put an if inside the loop to keep, skip or change items. Filtering, mapping and comparing neighbours show up in nearly every array question.