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

Python:

    sum(range(1000000000))
:)



Did you intend to demonstrate a very common off-by-one error in Python?


Probably should've used xrange as well. In the 2.x series, Python's range function returns an actual list.

I believe in 3.x range has been replaced with xrange.


I was assuming Python 3, but yes, you are correct.


> I believe in 3.x range has been replaced with xrange.

Correct.


It's not right. You should add one to the bound because "range" uses half-open intervals. Also, it only works in Python 3; in Python 2, it creates a list of a 1000000000 integers, so you should use "xrange" instead.


Yep, my bad. Didn't really think before I posted. And yes, I was assuming Python 3, so use xrange on Python 2.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

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

Search: