Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
RussianCow
on Aug 5, 2013
|
parent
|
context
|
favorite
| on:
Sum of 1 to 1000000000 in different programming la...
Python:
sum(range(1000000000))
:)
dragonwriter
on Aug 5, 2013
|
next
[–]
Did you intend to demonstrate a very common off-by-one error in Python?
knome
on Aug 5, 2013
|
parent
|
next
[–]
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.
RussianCow
on Aug 5, 2013
|
root
|
parent
|
next
[–]
I was assuming Python 3, but yes, you are correct.
masklinn
on Aug 5, 2013
|
root
|
parent
|
prev
|
next
[–]
> I believe in 3.x range has been replaced with xrange.
Correct.
DerekL
on Aug 5, 2013
|
prev
[–]
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.
RussianCow
on Aug 5, 2013
|
parent
[–]
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: