ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(sorted(['10', '9', '1.5']), sorted(['10', '9', '1.5'], key=float))
- A. ['10', '9', '1.5'] ['1.5', '9', '10']
- B. ['1.5', '9', '10'] ['1.5', '10', '9']
- C. ['1.5', '10', '9'] ['1.5', '9', '10']
- D. ['1.5', '9', '10'] ['10', '9', '1.5']
Correct answer: C. ['1.5', '10', '9'] ['1.5', '9', '10']
Plain sorting compares strings character by character, so '1.5' < '10' < '9'. Sorting with key=float compares numeric values, giving 1.5, 9, 10.
More Python Programming questions
- What is printed? python print(max('the', 'a', key=len), min(['b', 'B'], key=str.lower), ''.join(sorted('cab')), 'cab'.upper().swapcase())
- What is printed? python print(int(str(1020 + 1)[-1]) + len(str(1020)), 1020 + 1 == int(str(1020 + 1)))
- What is printed? python print(divmod(7.5, 2), divmod(-7.5, 2), 7.5 % -2, -7.5 // -2)
- What is printed? python print(-7 % 4, -7 % -4, 7 % -4, (-7) % 4 == -7 % 4)
- What is printed? python def edit(a, b): dp = [[0] (len(b) + 1) for in range(len(a) + 1)] for i in range(len(a) + 1): for j in range(len(b)…
- What is printed? python def lcs(a, b): dp = [[0] (len(b) + 1) for in range(len(a) + 1)] for i in range(1, len(a) + 1): for j in range(1…