What is the output of the following code? candidates = [(1,10), (2,9), (3,5), (4,8), (5,7), (6,6)] candidates.sort(key=lambda x: abs(x[0] - x[1]), reverse=True) print(candidates)
1Times asked
Aug 2026Last seen
Aug 2026First seen
💡 Model Answer
The key function computes the absolute difference between the two numbers in each tuple. The differences are: (1,10)->9, (2,9)->7, (3,5)->2, (4,8)->4, (5,7)->2, (6,6)->0. Sorting in descending order of these differences yields the sequence 9, 7, 4, 2, 2, 0. Python’s sort is stable, so tuples with equal keys keep their original order. Thus the final list is:
[(1, 10), (2, 9), (4, 8), (3, 5), (5, 7), (6, 6)].
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.
Get Assisting AI — Starts at ₹500