Occasionally I am in a scenario where I want to take every nth element from a list A and put it in list B, and all other elements into list C. Creating list B is basic python slicing. Is there an elegant way to create list C?
For example:
A = [0, 1, 2, 3, 4, 5, 6]
B = A[::3] # B = [0, 3, 6]
C = ??? # C = [1, 2, 4, 5]
The best I can come up with is this:
C = [x for x in A if x not in B]
But it seems silly to check membership for every element when we know mathematically which should be included. Especially because the scenario I am curious about tends to be make train/val/test splits in machine learning, where the lists can be very long. I am also open to elegant numpy solutions, but am curious if one exists in pure python as well.