ProgrammingModerateTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
values = {'x': [1, 2], 'y': [3]}
total = sum(len(v) for v in values.values())
keys = sorted(values, key=lambda k: len(values[k]), reverse=True)
print(total, keys)- A. 2 ['x', 'y']
- B. 3 ['x']
- C. 3 ['x', 'y']
- D. 3 ['y', 'x']
Correct answer: C. 3 ['x', 'y']
The total is 2 + 1 = 3. Sorting by length in descending order puts x first because it has two items.
More Python Programming questions
- What is printed? python print(int(' -0012 '), int('+5'), float('-.5'), float('5.'))
- What is printed? python x = 10 y = x y += 1 z = [x] z[0] += 5 print(x, y, z)
- What is printed? python a = list('abc') print(a.index('b'), ''.join(a[::-1]), a.pop(0), a)
- What is printed? python x = 5 print(f'{x=}', f'{x 2 = }', f'{"a" 2!r}')
- What is printed? python from math import ceil print(ceil(7 / 2), -(-7 // 2), (7 + 2 - 1) // 2)
- What is printed? python s = 'a b c' print(s.split(' '), s.split(), len(s.split(' ')) - len(s.split()))