Comment

Comment by kragen

Python is a little more readable, but both Python and Kotlin are perfectly clear in this case:

    sorted((u for u in users
           if u.last_name.startswith("S")),
           key=lambda u: u.last_name
    )[:3]
If last_name is a function, which it often would be in Python, it gets better:

    sorted((u for u in users
           if last_name(u).startswith("S")),
           key=last_name
    )[:3]
However, I think you probably got the sort key wrong if you're taking the first three items of the result. Maybe you meant key=abuse_score, reverse=True, or something.
parent kragen 7 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton