ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
words = ['apple', 'Bob', 'cat'] print(sorted(words, key=str.casefold)[0], sorted(words)[0], max(words, key=len))
- A. Bob Bob apple
- B. apple apple apple
- C. apple Bob apple
- D. apple Bob cat
Correct answer: C. apple Bob apple
casefold makes 'apple' the smallest word, while plain sorting puts uppercase 'Bob' first. max by length picks 'apple', the first of the longest words, since max keeps the first maximum it meets.
More Python Programming questions
- What is printed? python import heapq h = [(2, 'x'), (1, 'y'), (1, 'a')] heapq.heapify(h) heapq.heappush(h, (0, 'z'))…
- What is printed? python s = 'hello world' print(s.title(), s.swapcase()[:5], s.replace('l', '', 2))
- What is printed? python a = [[0] 2 for in range(2)] b = [[0] 2] 2 a[0][1] = 5 b[0][1] = 5 print(a, b)
- What is printed? python print(divmod(7, 2), divmod(-7, 2), divmod(7.5, 2))
- What is printed? python def outer(): res = [] for i in range(3): res.append(lambda: i) return [f() for f in res] def outer2(): return…
- What is printed? python print(10 18 % 7, (10 18 + 2) // 4, -(2 63) // (2 62))