ProgrammingHardTCS NQT · Wipro pattern
What is printed?
What is printed?
print(sorted([(2, 'b'), (1, 'z'), (2, 'a')], reverse=True))
- A. [(2, 'b'), (2, 'a'), (1, 'z')]
- B. [(2, 'a'), (2, 'b'), (1, 'z')]
- C. [(1, 'z'), (2, 'a'), (2, 'b')]
- D. [(2, 'b'), (1, 'z'), (2, 'a')]
Correct answer: A. [(2, 'b'), (2, 'a'), (1, 'z')]
Tuples compare the first element and then the second. In reverse order, the (2, 'b') tuple comes first, then (2, 'a'), then (1, 'z').
More Python Programming questions
- What is printed? python print(7 / 2 // 1, 7 // 2 / 1, -7 / 2 // 1, 7 % 2.5)
- What is printed? python print('abc'.find(''), 'abc'.count(''), ''.split(), ''.split(','))
- What is printed? python from fractions import Fraction print(Fraction(1, 3) == 1/3, Fraction(1, 3) == Fraction('0.3333333333333333')…
- What is printed? python print('Hello, World'.swapcase(), 'hello world'.title(), "it's here".capitalize(), 'ABC'.isupper())
- What is printed? python print(float('9007199254740993') == 9007199254740993, int(float('9007199254740993')), int(9007199254740993.0))
- What is printed? python print(len('abc' 1000000 + ''), 'abc' in 'x' 10 + 'abc', 'ab' < 'abc', [1, 2] < [1, 2, 0])