gpt-3.5-turbo-0314· OpenAI
Arena Human Preference 55K
write a quicksort in Python and output the sorting result of array [90, 78, 108, 0]
- User
write a quicksort in Python and output the sorting result of array [90, 78, 108, 0]
- Assistant
Sure, here's a quicksort implementation in Python:
pythondef quicksort(arr): if len(arr) <= 1: return arr else: 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)To output the sorting result of the array [90, 78, 108, 0], you can simply call the function and provide the array as an argument, like this:
pythonarr = [90, 78, 108, 0] sorted_arr = quicksort(arr) print(sorted_arr)This will output:
[0, 78, 90, 108]
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.