ProgrammingVery hardProduct-company MCQ pattern
What is printed?
What is printed?
print(len({1: 'a', True: 'b', 1.0: 'c'}), list({True: 1, 1: 2}.keys()))- A. 1 [1]
- B. 2 [True, 1]
- C. 1 [True]
- D. 3 [1, True, 1.0]
Correct answer: C. 1 [True]
1, True and 1.0 hash and compare equal, so each dict literal has one key. The dict keeps the first key object it saw, which is True in the second dict.
More Python Programming questions
- 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?
- Which statement about sorting 10^6 floats with sorted() in CPython is correct?