ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(sorted([2.0, 2, True, 1.5]))
- A. [True, 1.5, 2, 2.0]
- B. [True, 1.5, 2.0, 2]
- C. [1.5, True, 2.0, 2]
- D. [2, 2.0, True, 1.5]
Correct answer: B. [True, 1.5, 2.0, 2]
True compares as 1, so it comes first. 2.0 and 2 compare equal, and the stable sort keeps their input order, with 2.0 before 2.
More Python Programming questions
- What is printed? python print(len({1: 'a', True: 'b', 1.0: 'c'}), list({True: 1, 1: 2}.keys()))
- What is printed? python print(int(1e308) > 10308, float('1e-400'), 5e-324 / 2, 5e-324 / 2 == 0)
- What is printed? python print(1e-7 == 0.0000001, 1e-7, 0.0000001, 1.0e5 == 100000.0, 123e-2)
- What is printed? python print(7 // 2 2 + 7 % 2 == 7, -(7 // 2) 2 + -(7 % 2) == -7, (-7) // 2 2 + (-7) % 2)
- What is printed? python print(int('12' '34') + 1, '%d' % 3.9, '%i' % -3.9, '%+d' % 0)
- Which approach removes duplicates from a list while keeping the first-seen order, in O(n) average time?