ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(min([(1, 'b'), (1, 'a')], key=lambda t: t[0]), max(['aa', 'b', 'cc'], key=len))
- A. (1, 'a') cc
- B. (1, 'b') cc
- C. (1, 'a') aa
- D. (1, 'b') aa
Correct answer: D. (1, 'b') aa
min and max return the first item that attains the best key, so the tie on key 1 gives (1, 'b'). For max with key=len, 'aa' is the first longest item among 'aa' and 'cc'.
More Python Programming questions
- What is printed? python d = dict.fromkeys(['a', 'b'], []) d['a'].append(1) print(d)
- What is printed? python list = [1] try: print(list(range(2))) except TypeError as e: print(e)
- What is printed? python import heapq g = {'A': [('B', 1), ('C', 4)], 'B': [('C', 2), ('D', 5)], 'C': [('D', 1)], 'D': []} dist = {k…
- What is printed? python print(pow(10, 100, 7), pow(2, 10, 1000), pow(7, 0, 7))
- What is printed? python x = 5 print(x if x > 3 else 0 if x == 3 else -1, 2 -1, 7 % 3 2)
- Which technique is the reliable fix for a recursive DFS on a path graph with n = 10^5 nodes in Python, which otherwise raises…