← Back to Data Structures & Algorithms
Question 531
Partition Around A Pivot
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
Sign in to use hintsTopics:
Data Structures & Algorithms
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.