← Back to challenges

Even Odd Partition

PythonHardarrayshigher_order_functions

Instructions

Write a function that partitions the list into two sublists: one with all even integers, and the other with all odd integers. Return your result in the following format:

[[evens], [odds]]

Examples

even_odd_partition([5, 8, 9, 2, 0]) ➞ [[8, 2, 0], [5, 9]]

even_odd_partition([1, 0, 1, 0, 1, 0]) ➞ [[0, 0, 0], [1, 1, 1]]

even_odd_partition([1, 3, 5, 7, 9]) ➞ [[], [1, 3, 5, 7, 9]]

even_odd_partition([]) ➞ [[], []]

Notes

  • Return two empty sublists if the input is an empty list.
  • Keep the same relative ordering as the original list.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Identical Sublists