chatgpt-4o-latest-20250326· OpenAI
LMArena Human Preference 140K
write quicksort in python in the most simple, short and easy to understand way
- User
write quicksort in python in the most simple, short and easy to understand way
- Assistant
Here's a simple, short, and easy-to-understand implementation of Quicksort in Python using recursion:
def quicksort(arr): if len(arr) <= 1: return arr pivot = arr[0] left = [x for x in arr[1:] if x < pivot] right = [x for x in arr[1:] if x >= pivot] return quicksort(left) + [pivot] + quicksort(right)Example usage:
print(quicksort([3, 6, 1, 5, 2, 4])) # Output: [1, 2, 3, 4, 5, 6]How it works:
- If the list has 0 or 1 element, it's already sorted.
- Pick the first element as the pivot.
- Split the rest into:
left: all elements less than the pivot.right: all elements greater than or equal to the pivot.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.