← Back to Data Structures & Algorithms
Question 536
Is The List Sorted
Is The List Sorted
Write is_sorted(values: list[int]) -> bool that returns True when the list is in non-decreasing order (equal neighbours are fine) and False otherwise, by comparing each element with the one before it in a single loop over range(1, len(values)). An empty or one-element list counts as sorted. Do NOT write a main block or any top-level test code; the tests construct the calls. Input: one line of space-separated integers (possibly empty); the tests print the boolean your function returns.
Expected Output:
True= newline. The output ends with a newline — print one after the last line.
Hints3 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.