CJCoding With Joseph
15free / daySign inCreate account

Partition Around A Pivot

Write partition(values: list[int], pivot: int) -> tuple[list[int], list[int], list[int]] that splits the values into three new lists, in their original order: those less than the pivot, those equal to it, and those greater, using one loop with an if / elif / else chain and append(). This is the step quicksort repeats on each piece. Do NOT write a main block or any top-level test code; the tests construct the calls. Input: two lines, a space-separated list of integers (possibly empty) and then the pivot; the tests print the three returned lists on three lines, less first.

Expected Output:

[3, 1]
[5, 5, 5]
[8, 9]

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
Data Structures & Algorithms
📥 Auto-Input:
5 3 8 5 1 9 5\n5\n
This input is automatically fed to your program's stdin
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.