Chapter 2 - A Crash Course into Python - Lists section errors.
Author: stouneCreated Nov 30, 2025Updated Nov 30, 2025
A Crash Course into Python chapter - lists section
The slicing explanation contains mistakes:
crash_course_in_python.py Lines 149:156
first_three = x[:3] # [-1, 1, 2]
three_to_end = x[3:] # [3, 4, ..., 9]
one_to_four = x[1:5] # [1, 2, 3, 4]
last_three = x[-3:] # [7, 8, 9]
without_first_and_last = x[1:-1] # [1, 2, ..., 8]
copy_of_x = x[:] # [-1, 1, 2, ..., 9]
every_third = x[::3] # [-1, 3, 6, 9]instead of index -1 in the explanations/comments should be used 0. -1 refers to the last element of the list/slice.
See also slicings
The lower and upper bound expressions, if present, must evaluate to plain integers; defaults are zero and the sys.maxint, respectively.
Source: joelgrus/data-science-from-scratch