I would like to use a combination of options of Partition in a way that I can't seem to find in the documentation.
Given example input {a,b,c,d,e,f,g}
, I would like output {a,b,c,d},{c,d,e,f},{e,f,g}
, i.e. an offset partition where one final element is allowed to be smaller at the end of the list.
Partition[{a,b,c,d,e,f,g}, UpTo[4], 2]
comes close, but because it continues to run in steps of 2 it gives an extra {g}
which I do not want. Using Upto
without the offset gives what I want, but I need the offset. Various other combinations get me near but nothing quite fits. I'm aware I could fiddle with this and create some function that goes through and deletes lists that are too small, but Partition has so many nice options that I feel I must be missing something.
Edit: A few people have given answers that work for the given list, but in case I wasn't clear I need this to work for varying partition and offset size and on lists of unknown length, which I really think must be possible.