Home › Interview Questions › What is the issue with calling scores.sort() and t…

What is the issue with calling scores.sort() and then iterating over scores in the following code?

🟢 Easy Debugging Junior level
1Times asked
Oct 2026Last seen
Oct 2026First seen

💡 Model Answer

In Python, list.sort() sorts the list in place and returns None. If you write scores.sort(); for score in scores:, the for loop will try to iterate over None, raising TypeError: 'NoneType' is not iterable. The fix is to either use sorted(scores) which returns a new sorted list, or simply call scores.sort() and then iterate over scores without assigning the result.

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