Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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
            ...


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

Search: