4.2.9 Sorting Lists: sort() vs. sorted()

Unit: Unit 4: Strings, Lists, and Tuples • Interactive Practice

Quick Answer & Summary:

Interactive Python programming tutorial and practice in your browser.

Interactive Challenge (Run Live in Browser):

# Sort lists in-place with sort() and compare with sorted()
scores = [88, 72, 95, 64, 81]

# 1. Non-destructive sort using built-in sorted()
ascending_copy = sorted(scores)

# 2. In-place descending sort using scores.sort(reverse=True)
scores.sort(reverse=True)

print("Non-destructive sorted copy:", ascending_copy)
print("In-place descending sorted original:", scores)
Open in Live Interactive Python Sandbox →