How to slice with start stop step

In Python I can do

>>> a = [1, 2, 3, 4, 5, 6, 7, 8]
>>> a[3:7:2]
[4,6]

Here I am selecting the indices between 3 and 7 with a step size of two. However in Julia I get

julia> a = [1, 2, 3, 4, 5, 6, 7, 8]
julia> a[3:7:2]
Int64[]

How can I slice with start stop step in Julia? Ideally I’d also like to do

julia> a[3:end:2]

Thanks

start:step:stop is the correct order!

2 Likes

Oh my, that was easy wasn’t it! Thank you.