ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(sorted('bAcB', key=str.upper), sorted('bAcB'))- A. ['A', 'B', 'c', 'b'] ['A', 'b', 'B', 'c']
- B. ['A', 'b', 'B', 'c'] ['A', 'b', 'c', 'B']
- C. ['A', 'b', 'c', 'B'] ['A', 'B', 'b', 'd']
- D. ['A', 'b', 'B', 'c'] ['A', 'B', 'b', 'c']
Correct answer: D. ['A', 'b', 'B', 'c'] ['A', 'B', 'b', 'c']
With key=str.upper, the two b's compare equal and keep their input order, so b comes before B. Without a key, uppercase letters sort before lowercase, giving A, B, b, c.
More Python Programming questions
- What is printed? python print(int('0' + '9' 3) + 1, int('9' 3 + '0') + 1)
- What is printed? python print(7 // 0.5, 7 % 0.5, -7 // 0.5)
- What is printed? python print(0.5 1074 == 0, 5e-324 > 0, 5e-324 / 2 == 0)
- What is printed? python print('abcabc'.replace('abc', 'x', 1), 'aaaa'.replace('aa', 'b'), 'aaa'.replace('', '-'))
- What is printed? python print('Mississippi'.lower().count('s'), 'Mississippi'.find('ss'), 'Mississippi'.rfind('ss'))
- What is printed? python print(float('-0') == 0.0, str(float('-0')), str(float('+0')))