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

you could use a list comprehension to do the same thing:

print sum([x for x in xrange(101)])

although the n(n+1)/2 is probably the best, I'd just like to point that out because I wish someone would have pointed out list comprehensions to me earlier :)



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

Search: