practicepython.in
python exercises
171 exercises

Working with sequences

Lists, order, and the arithmetic of positions. Every one of these is something you will write in a real codebase within a month, and every one has an edge case that decides whether it is right.

12 exercisesdifficulty 1–3~200 min in total
The last few, and the zero that is not zero negative slicing, the -0 trap ~12 min Chunk a sequence slicing, range with a step ~15 min Remove duplicates, keep the order sets for membership, the seen pattern ~15 min Flatten one level of nesting nested comprehensions, reading order ~15 min Rotate a list without falling over modulo for wrapping, slice and rejoin ~15 min The total so far, at every step carrying state through a loop, accidentally quadratic ~15 min One cut, two pieces, nothing lost complementary slices, slices clamp ~15 min Taking turns until everyone is done *args, round-robin ~20 min The longest stretch of the same thing consecutive grouping, best-so-far ~20 min Page through a list 1-based vs 0-based, slicing ~20 min Rows become columns zip(*rows), unpacking into a call ~18 min Sliding windows over a sequence overlapping slices, the range bound ~20 min