struggling with these problems

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed Jan 30 05:43:56 CET 2013


On Wed, 30 Jan 2013 03:59:32 +0000, MRAB wrote:

> Python uses half-open ranges (and counts from 0), which means that the
> start index is included and the end index is excluded.
> 
> Therefore, worst_offenders[5:6] means the slice from index 5 up to, but
> excluding, index 6; in other words, an empty list.

Er, no. It's a one-element list: index 5 is included, index 6 is excluded.

py> L = list("abcdefgh")
py> L[5:6]
['f']




-- 
Steven



More information about the Python-list mailing list