We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
This challenge requires the whole list to be loaded into memory. Unless you are saving each student record to a file as you read it, there is no other option. And we're told there are never more than 5 students in the input.
I use generators rather than comprehensions wherever it is possible and reasonable, but this isn't one of those situations. If you are doing this with nested lists (a dict would be more efficient), the whole list has to be traversersed at least twice, depending on your sorting strategy.
Hard to debug? Comprehensions have become core to Python. They beat hand-crafted for loops for several reasons:
More expressive (if not abused)
Less fragile and error prone
Can often easily be turned into generators for memory efficiency.
Learn them. Modern Python is full of them. Which of these is clearer?
Nested Lists
You are viewing a single comment's thread. Return to all comments →
This challenge requires the whole list to be loaded into memory. Unless you are saving each student record to a file as you read it, there is no other option. And we're told there are never more than 5 students in the input.
I use generators rather than comprehensions wherever it is possible and reasonable, but this isn't one of those situations. If you are doing this with nested lists (a dict would be more efficient), the whole list has to be traversersed at least twice, depending on your sorting strategy.
Hard to debug? Comprehensions have become core to Python. They beat hand-crafted for loops for several reasons:
Learn them. Modern Python is full of them. Which of these is clearer?