still not entirely sure what the :: does in grid[::d], apart from take every d'th y
The slice syntax is
grid[start:stop:stride]
and you can omit any, so start defaults to zero, stop to -1 (which means the end, since negative indices count backwards), and stride defaults to 1.
grid[start]
start
[start,start+1)
[start:stop]
[start::stride]
stride
Thanks - i had never seen the stride part of the syntax, always just sliced [x:y]
It's one of those nice little things they really paid attention to. For example, you can reverse any sequence by using a negative stride.
@lf started
London Fixed Gear and Single-Speed is a community of predominantly fixed gear and single-speed cyclists in and around London, UK.
This site is supported almost exclusively by donations. Please consider donating a small amount regularly.
The slice syntax is
and you can omit any, so start defaults to zero, stop to -1 (which means the end, since negative indices count backwards), and stride defaults to 1.
grid[start]
just gives you the element at indexstart
(ie, the half-open interval[start,start+1)
in maths language),[start:stop]
gives you the sub-sequence/sub-string with default stride 1,[start::stride]
would give you everystride
'th element fromstart
to the end, etc.