ProgrammingModerateTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(sorted([(-1, 'b'), (-1, 'a'), (0, 'c')]), max([(1, 'z'), (1, 'a')]))
- A. [(-1, 'a'), (-1, 'b'), (0, 'c')] (1, 'a')
- B. [(0, 'c'), (-1, 'a'), (-1, 'b')] (1, 'z')
- C. [(-1, 'a'), (-1, 'b'), (0, 'c')] (1, 'z')
- D. [(-1, 'b'), (-1, 'a'), (0, 'c')] (1, 'a')
Correct answer: C. [(-1, 'a'), (-1, 'b'), (0, 'c')] (1, 'z')
Tuples compare by the first field and then the second. max keeps the larger tuple, (1, 'z'), since 'z' is larger than 'a'.
More Python Programming questions
- What is printed? python x = 0 for i in range(5): x += i if i % 2 else -i print(x)
- What is printed? python it = iter([3, 1, 0, 5, 0]) out = [] for x in iter(lambda: next(it), 0): out.append(x) print(out, list(it))
- What is printed? python s = 'key=value=end' print(s.partition('='), s.rpartition('='), 'a b'.split(' '))
- What is printed? python def shift(s, k): return ''.join(chr((ord(c) - 97 + k) % 26 + 97) if c.islower() else c for c in s)…
- What is printed? python def closest3(a, t): a = sorted(a) best = None for i in range(len(a) - 2): l, r = i + 1, len(a) - 1 while l < r: s…
- What is printed? python print(0.0 == -0.0, -0.0, 1e16 + 1 == 1e16, 2 53 + 1 == 2 53)