ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(sorted([3, 1, 2], key=lambda x: -x)[0], max([3, 1, 2], key=lambda x: -x))
- A. 1 3
- B. 3 3
- C. 1 1
- D. 3 1
Correct answer: D. 3 1
Sorting by -x puts the largest value first, so the first item is 3. max by key -x returns the element whose negation is largest, which is 1.
More Python Programming questions
- What is printed? python print([x for x in range(20) if x % 3 == 0 and x % 4 == 0])
- What is printed? python print(len({(i, j) for i in range(3) for j in range(3) if i <= j}))
- What is printed? python print(sum(1 for c in 'Hello World' if c.isupper()), 'Hello World'.count('o'))
- What is printed? python print(float('1e400'), -float('1e400'))
- What is printed? python print(str(1e16), str(1e15), str(123456789.0))
- What is printed? python print(0.1 3, 1.1 1.1)