ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(sorted([3, 1, 2], key=lambda x: -x)[0], sorted('bca', key=lambda c: c > 'a'))- A. 1 ['a', 'b', 'c']
- B. 2 ['b', 'c', 'a']
- C. 3 ['a', 'b', 'c']
- D. 3 ['a', 'c', 'b']
Correct answer: C. 3 ['a', 'b', 'c']
Sorting by negated value puts 3 first. The key c > 'a' is False only for a, so a sorts first, and the stable order keeps b before c.
More Python Programming questions
- What is printed? python print(int('10', 36) == 36, int('Z', 36), int('z', 36) + 1, int('10', 2) == 2)
- What is printed? python x = [1, 2, 3] print(x.pop(), x.pop(0), x, x.insert(0, 9) or x)
- What is printed? python print(max(map(len, ['a', 'bbb', 'cc'])), min(len(s) for s in ['a', 'bbb']), sum(len(s) for s in ['ab', 'c']))
- What is printed? python print(float('1e2') == 100, int(float('1e2')), str(float('1e2')), int('100'))
- What is printed? python print(round(1.0000000000000002, 15) == 1, 1.0000000000000002 == 1, 1.0000000000000002 - 1 == 2.220446049250313e-16)
- What is printed? python s = 'hello world' print(s.title().split()[1][::-1], s.rsplit(' ', 1)[0], s.count('o', 5))