ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
print(len({'a': 1, 'b': 2}), len({'a', 'a', 'b'}), len(dict.fromkeys('hello')))- A. 2 3 5
- B. 2 2 4
- C. 2 2 5
- D. 1 2 4
Correct answer: B. 2 2 4
A dict literal with two distinct keys has two entries, and a set literal removes the duplicate a. dict.fromkeys over 'hello' keeps the four distinct letters h, e, l and o.
More Python Programming questions
- What is printed? python print(sorted({'b': 2, 'a': 3}.items(), key=lambda kv: kv[1])[0][0], list({'b': 2, 'a': 3})[-1])
- What is printed? python print(3 3 0, (3 3) 0, 0 3 0, (0 3) 0)
- What is printed? python import math print(math.isclose(0.1 + 0.2, 0.3), math.isclose(0.0, 1e-10), math.isclose(0.0, 1e-10, abstol=1e-9))
- What is printed? python print(int(9.99), int(-9.99), round(9.99), round(-9.99), 0)
- What is printed? python def span(p): st, out = [], [] for i, x in enumerate(p): while st and p[st[-1]] <= x: st.pop() out.append(i…
- What is printed? python def peak(a): lo, hi = 0, len(a) - 1 while lo < hi: mid = (lo + hi) // 2 if a[mid] < a[mid + 1]: lo = mid + 1 else…