ProgrammingModerateGATE CS · Product-company placement
What is printed?
What is printed?
words = ["kiwi", "fig", "apple", "date"] print(sorted(words, key=len), max(words, key=len), min(words))
- A. ['fig', 'kiwi', 'date', 'apple'] apple apple
- B. ['fig', 'date', 'kiwi', 'apple'] apple apple
- C. ['fig', 'kiwi', 'date', 'apple'] apple fig
- D. ['apple', 'date', 'fig', 'kiwi'] apple apple
Correct answer: A. ['fig', 'kiwi', 'date', 'apple'] apple apple
A stable sort by length keeps 'kiwi' before 'date' (both length 4) in their original order. min without a key compares alphabetically, so 'apple' is smallest.
More Python Programming questions
- What is printed? python import copy class Node: def init(self): self.kids = [] a = Node() a.kids.append(a) b = copy.deepcopy(a)…
- What is printed? python a = [1, [2, 3]] b = a[:] c = list(a) d = [a] a[1] += [4] a[0] += 10 print(b, c is d, d[1] is a[1])
- What is printed? python s = "abc" it = iter(s) print(next(it), "".join(it), list(it), [c for c in s if c in "ab" or c == "z"])
- What is printed? python def f(n): if n == 0: return [] return [n] + f(n - 1) if n % 2 else f(n - 1) + [n] print(f(5))
- What is printed? python x = 1 def f(): print(x, end=" ") def g(): x = 2 f() g() h = lambda: x x = 3 print(h())
- What is printed? python def outer(): v = "a" def inner(): return v v = "b" r1 = inner() del v try: return r1, inner() except NameError as…