gpt-4o-mini-2024-07-18· OpenAI
WildChat-4.8M (AI2)
write python to sort a list
- User
write python to sort a list
- Assistant
Here's a simple example of how to sort a list in Python using the built-in
sorted()function and thesort()method of a list:Using
sorted()FunctionThe
sorted()function returns a new sorted list from the elements of any iterable (like a list).python# Example list numbers = [5, 2, 9, 1, 5, 6] # Sort the list sorted_numbers = sorted(numbers) # Output the sorted list print("Original list:", numbers) print("Sorted list:", sorted_numbers)Using Method