Keep the odd ones
Inputs
values is a list of 0 to 14 whole numbers, each from -30 to 30.
Your tasks
- Create an empty list
odds. - Use a loop over
valuesand add each odd number toodds, in the original order. - Complete
keepOddso it returnsodds. Return it, do not print it.
Example
With values = [4, 7, -3, 10, 5], keepOdd returns [7, -3, 5].
Rules
- Negative numbers can be odd. -3 is odd.
Test data
TEST DATA 1: values is [4, 7, -3, 10, 5]
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.