ProgrammingHardTCS NQT · Accenture
What is printed?
What is printed?
print(max([1, 5, 3], key=lambda v: -v))
- A. 5
- B. 3
- C. -7
- D. 1
Correct answer: D. 1
The key negates each value, so the largest key belongs to the smallest value, 1. max returns the original element, not its key.
More Python Programming questions
- What is printed? python print(list(map(int, '1 2 3'.split()))[::-1])
- What is printed? python print(f'{7:03d}|{-7:d}|')
- What is printed? python x = 7 print(f'{x=}', f'{x 2 = }', f'{"a"!r:>4}')
- What is printed? python import keyword print(keyword.iskeyword('match'), keyword.issoftkeyword('match'), keyword.iskeyword('None')…
- What is printed? python print({'a': 1} | {'a': 2, 'b': 3}, {'a': 1} | {}, dict(a=1) == {'a': 1})
- What is printed? python print(format(1234567.891, ',.2f'), format(0.000123, 'e'), format(12, '>5'), format(3, '03'))