Hacker News new | ask | show | jobs
by yeukhon 4480 days ago
Slice has always been a painful adventure for me. I always forget that [1:3] is not all inclusive. It's actually just range from 1 to 2.

I believe in 2.7 zip is still returning a list rather than an iterator (izip in Python 2, zip in Python 3+).

Another unappreciated stdlib is definitely functools. mock is also another awesome stdlib.

functools, collections and itertools are definitely useful to make things faster. Also check out the list of stdlib. http://docs.python.org/2/library/

2 comments

> I always forget that [1:3] is not all inclusive. It's actually just range from 1 to 2.

Just remember that for positive indices, len(slice(n,m)) == m - n

Slices make sense when you realize that [n:n] is always empty, and [:n] + [n:] is always the whole list. From these two identities, all else follows.