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

As a trivial example, if you want to get the sum of the first n numbers, that's `sum(range(n+1))` in Python. Or if you want to get all the prime numbers <= n, find the triangular numbers, etc. In general you end up with a lot of `n+1`s and it's easy to lose track or miss some, and end up with a silent, non-crashing error that produces the wrong result because you're accidentally leaving out the last element of your input.


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

Search: