Q23
1 markShort AnswerSection B

To create a new list L1 containing the elements of list L arranged in ascending order, without modifying list L.

Python Revision Tour
Sorting a List — sorted()
Official Answer

Required statement:

``python

L1 = sorted(L)

`

The built-in sorted() function returns a NEW list containing the elements of L arranged in ascending order, while leaving the original list L` completely unchanged.

sorted() functionlist sortingascending ordernon-destructive sortL.sort() vs sorted(L)built-in functionPython lists

Marking Scheme

  • 11 mark for the correct statement `L1 = sorted(L)`; equivalent forms like `L1 = sorted(L, reverse=False)` also accepted.

Hint

Use the function that RETURNS a new sorted list rather than the method that sorts the list in place.

Quick Oral Answer

L1 = sorted(L) creates a new ascending-order list from L without changing L, because sorted() always returns a fresh list rather than sorting in place.

Analysis & Explanation

This question tests the important distinction between Python's sort() method and sorted() function.


Why sorted(L) is the correct choice

  • sorted(L) takes any iterable and returns a brand-new sorted list, by default in ascending order.
  • The original list L is never modified by sorted(), satisfying the requirement to leave L untouched.

Common confusion

  • L.sort() sorts the list L IN-PLACE and returns None — using L1 = L.sort() would incorrectly make L1 equal to None while also modifying L, which violates the question's condition.

Common Mistakes

  1. 1Writing `L1 = L.sort()`, which sorts L in place and stores `None` in L1 — this fails to create a separate ascending list and also modifies L.
  2. 2Assuming `sorted()` modifies the original list L, when in fact it only returns a new list, leaving L unchanged.

Interesting Facts

Python's built-in sort (used internally by both `sort()` and `sorted()`) is called Timsort, a hybrid of merge sort and insertion sort designed for real-world data.

`sorted()` works on ANY iterable — lists, tuples, strings, dictionaries (sorts keys) — always returning a list, unlike `sort()` which is a list-only method.

Spotted a mistake or something unclear?

Tell us — we fix reported answers fast.

Frequently Asked Questions

What is the difference between L.sort() and sorted(L)?

L.sort() sorts the list L in place and returns None, modifying the original list. sorted(L) returns a brand-new sorted list and leaves L unchanged.

How do you sort a list in descending order using sorted()?

Pass the reverse=True argument: L1 = sorted(L, reverse=True).