ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(list(dict.fromkeys('mississippi')))- A. ['m', 's', 'i', 'p']
- B. ['m', 'i', 's', 'p']
- C. ['i', 'm', 's', 'p']
- D. ['m', 'i', 's', 'p', 'i']
Correct answer: B. ['m', 'i', 's', 'p']
dict.fromkeys keeps the first occurrence of each key, in insertion order. This is a common way to remove duplicates while keeping order.
More Python Programming questions
- What is printed? python print(any([]) or all([]) and 'x')
- What is printed? python s = 'hello' print(s[1:-1][::-1], s[-1:0:-2])
- What is printed? python d = {} d.setdefault('k', []).append(1) d.setdefault('k', []).append(2) print(d)
- What is printed? python print(1 / 3 + 1 / 3 + 1 / 3 == 1.0, 0.1 + 0.7)
- What is printed? python print(sorted([(-1, 'b'), (-1, 'a'), (0, 'c')]), max([(1, 'z'), (1, 'a')]))
- What is printed? python x = 0 for i in range(5): x += i if i % 2 else -i print(x)