Question:

Write a Python statement to perform the following tasks: (USE BUILT_IN FUNCTIONS / METHODS ONLY)

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

(ii) A statement to check whether the given character, ch is an alphabet or a number.

Show Hint

Use the built-in sorted(L) for a new sorted list, and the string method isalpha() (or isdigit()) to test a character.
Updated On: Oct 20, 2026
Show Solution
collegedunia
Verified By Collegedunia

Solution and Explanation

Step 1: Part (i): new sorted list, L unchanged:
The list method L.sort() sorts L itself, so it changes L. We must not use it.
The built-in function sorted() returns a NEW list in ascending order and leaves L as it is.
L1 = sorted(L)
Check with L = [5, 2, 9, 1]: L1 becomes [1, 2, 5, 9] and L is still [5, 2, 9, 1].

Step 2: Part (ii): alphabet or number:
The string method isalpha() returns True when every character is a letter, and False otherwise.
ch.isalpha()
For ch = 'a' it gives True, so ch is an alphabet. For ch = '7' it gives False.
To test for a number, use ch.isdigit(). It gives True for '7' and False for 'a'.
The two checks can be joined in one statement: print('Alphabet' if ch.isalpha() else 'Number')

Final Answer:
(i) L1 = sorted(L)
(ii) ch.isalpha() (True means alphabet; use ch.isdigit() to test for a number)
Was this answer helpful?
0
0