If not, then a canonical name for a function? ‘Cycle’ makes sense to me, but that’s taken.
The example in the header is written for clarity and brevity. Real cases I’m working with have a lot of repetition.
(e.g., I want [1, 1, 0, 0, 0, 2, 1] to “match” [0, 0, 2, 1, 1, 1, 0])
This type of thing is obscuring my algorithm and filling my code with otherwise useless repetition.
You can get the cycles of the list with:
You can then check if b is a cycle of a with:
If the length of the list is long, or if want to make multiple comparison to the same cycles, it may be beneficial (performance wise) to embed the results in a set.
You can prevent necessarily constructing all the cycles by embedding the equality check in the list and using any:
You could also achieve this effect by turning the
cyclesfunction into a generator.