Hacker News new | past | comments | ask | show | jobs | submit login

NO. That is not more readable, and is warned against in most style guides and code-quality books.

In the original, at a glance I know exactly what is going on.

In your version, I have to read the whole sentence carefully to notice that it's even a conditional and not a normal assignment, and then I have to mentally unpack it to understand the logic that you're trying to implement. If/else should never be a one-liner.

Good code is boring code :)




Yup, but the right way to do it would be a defaultdict, or a Counter anyway.

    from collections import defaultdict

    def count_names():
        names = defaultdict(int)
        for name in sys.stdin.readlines():
            name = name.strip()
            names[name] += 1
            ...




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: