ProgrammingModerateTCS NQT · Infosys
Which statement about sorting in Python is correct?
- A. list.sort() sorts in place and returns None, while sorted() returns a new list
- B. list.sort() returns the sorted list, while sorted() sorts in place
- C. sorted() changes the original list and returns None
- D. sorted() is stable but list.sort() is not
Correct answer: A. list.sort() sorts in place and returns None, while sorted() returns a new list
list.sort is a method that mutates the list and returns None. sorted accepts any iterable and returns a new list, and both sorts are stable.
More Python Programming questions
- What is printed? python print(oct(-8), hex(-255), bin(0), format(-5, 'b'))
- What is printed? python n = 13 print(n ^ (n >> 1), [bin(i ^ (i >> 1)) for i in range(4)])
- What is printed? python print(~5 == -6, ~(-5) == 4, (-5) >> 1 == -2, -5 // 2 == -3)
- What is printed? python import unicodedata print(unicodedata.normalize('NFC', 'eu0301') == 'é', len(unicodedata.normalize('NFD', 'é'))…
- What is printed? python print('a1'.isalnum(), '١'.isalnum(), ' '.isspace(), ''.isspace(), 'u00a0'.isspace())
- What is printed? python def fermatinverse(a, p): return pow(a, p - 2, p) print(fermatinverse(3, 7) == pow(3, -1, 7), 3 fermatinverse(3, 7)…