Demonstrate the difference between sort() and sorted()
A medium Python interview practice problem on DataDriven. Write and execute real python code with instant grading.
- Domain
- Python
- Difficulty
- medium
Problem
Demonstrate the difference between sort() and sorted(). Given nums = [5, 2, 8, 1]. First use sorted() to create a new sorted list and print it. Then print the original nums to show it is unchanged.
Practice This Problem
Solve this Python problem with real code execution. DataDriven runs your Python code in a real environment and grades it automatically.