ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
words = ['bb', 'a', 'ccc'] print(max(words), max(words, key=len), min(words, key=len), sorted(words, key=lambda w: (len(w), w))[-1])
- A. bb ccc a ccc
- B. ccc ccc a bb
- C. ccc bb a ccc
- D. ccc ccc a ccc
Correct answer: D. ccc ccc a ccc
Without a key, max compares strings alphabetically, so 'ccc' wins. The key len picks the longest and shortest words, and the sorted list ends with the longest word.
More Python Programming questions
- What is printed? python print(len(f'{1234.5:.0f}'), f'{1234.5:.0f}', f'{1235.5:.0f}', f'{-1234.5:.0f}')
- What is printed? python print(1e3 == 103, int(1e3) is not None, 1e3 // 1 == 103, type(1e3 // 1).name)
- What is printed? python print('%x' % -255, '%o' % 8, '%e' % 0.0, '%.0e' % 12345)
- What is printed? python print(5 & 6 | 1, 5 & (6 | 1), 5 ^ 6 & 1, 1 | 2 ^ 3 & 4)
- What is printed? python print(-1 >> 1, -1 << 2, -5 >> 10, 5 >> -0 if False else 0)
- What is printed? python print(bin(-1 & 0b111), (-1) & 0xF == 15, -16 >> 2, -15 >> 2)