ProgrammingHardTCS NQT · Wipro pattern
What is printed?
What is printed?
data = [('x', 3), ('y', 1), ('z', 3)]
print(max(data, key=lambda t: t[1]), min(data, key=lambda t: -t[1]))- A. ('x', 3) ('x', 3)
- B. ('z', 3) ('z', 3)
- C. ('x', 3) ('y', 1)
- D. ('y', 1) ('x', 3)
Correct answer: A. ('x', 3) ('x', 3)
max and min return the first element that reaches the best key. The first item with the largest value is ('x', 3), and the key -t[1] is smallest first for that same element.
More Python Programming questions
- What is printed? python print(0.1 + 0.2 == 0.30000000000000004, 0.1 + 0.2 - 0.30000000000000004 == 0, '%.20f' % (0.1 + 0.2))
- What is printed? python s = '42' print(s 2 + '!' if s.isdigit() else '', int(s) 2, s.zfill(4) + '|' + s.rjust(4, '0') + '|' + s.ljust(4…
- What is printed? python print(sum(map(int, '123456789')) == 45, sum(map(int, str(99))), 99 % 9)
- What is printed? python print('a' 3 < 'b', 'a' 3 < 'aa', 'aaa' > 'aab', 'aa' + 'b' > 'aab')
- What is printed? python x = 5 print(x // 2 2 == x, x / 2 2 == x, 5 / 2 == 2.5, 5 // 2.0 == 2)
- What is printed? python print(bytes('é', 'utf-8'), 'é'.encode('latin-1'), len('é'.encode('latin-1')) == len('é'.encode('utf-8')))