Aside: Negative Stride

Here’s a truly handy thing to learn about Python. First, in addition to slicing lists, it has an ability to stride through them. The default stride is `[::1]`, which simply means walk through everything, but you could choose every other item in a list quite simply: `[::2]`. But here’s the one that got me: you can stride backwards through a list, so reversing the order of a list is this simple:

backwards = a_list[::-1]

That is *so* useful.

Leave a Reply