• + 6 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:

    1. More expressive (if not abused)
    2. Less fragile and error prone
    3. Can often easily be turned into generators for memory efficiency.

    Learn them. Modern Python is full of them. Which of these is clearer?

    validGroup = all(validUser(user) for user in group)
    
    for user in group:
        if not validUser(user):
            validGroup = False
            break
    else
        validGroup = True