ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(max('abc', 'abd', key=lambda s: s[::-1]), min('ba', 'ab', key=len))- A. abd ba
- B. abc ab
- C. abd ab
- D. abc ba
Correct answer: A. abd ba
Reversed, 'abc' becomes 'cba' and 'abd' becomes 'dba', so the larger key is 'dba' and max returns 'abd'. min by length ties on both words, and min keeps the first, which is 'ba'.
More Python Programming questions
- What is printed? python print(sorted([1, 10, 2], key=lambda x: str(x)[0]))
- What is printed? python print(0.1 + 0.1 == 0.2, 0.1 + 0.1 + 0.1 == 0.3, 0.2 + 0.2 == 0.4)
- What is printed? python print(list(range(2, 20, 5)), list(range(-1, -10, -4)))
- What is printed? python print(len(str(71000)), 71000 % 10)
- What is printed? python print(10 -3 1000 == 1, 10 -3 1000)
- What is printed? python print(int('12' 2) + int('3' 2), len({'x' n for n in range(4)}))