ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(sorted([(1, 'b'), (1, 'a'), (0, 'z')], reverse=True)[0])
- A. (1, 'b')
- B. (0, 'z')
- C. (1, 'a')
- D. (1, 'z')
Correct answer: A. (1, 'b')
Reverse sorting on tuples compares the first fields, then the second. (1, 'b') is the largest tuple because 'b' is greater than 'a' when the first fields tie.
More Python Programming questions
- What is printed? python print(list(map(len, ['', 'ab', 'abc'])), sum(map(len, ['', 'ab', 'abc'])))
- What is printed? python print(10 in range(0, 20, 5), 11 in range(0, 20, 5))
- What is printed? python print(sum(range(1, 101)) 2 - sum(i i for i in range(1, 101)))
- What is printed? python print(len(str(264)), sum(map(int, str(264))))
- What is printed? python print(all(int(c) % 2 == 0 for c in '24680'), any(c in 'aeiou' for c in 'rhythm'))
- What is printed? python print(''.join(c.upper() if i % 2 else c for i, c in enumerate('python')))