I have a Python list
num_list = list(range(1,33))
And need every other pair of numbers in the list, like this:
[1, 2, 5, 6, 9, 10 ... ]
I’ve figured out how to exclude certain indices from the list, like this
num_list[2::3]
> [3, 6, 9, 12, 15, 18, 21, 24, 27, 30]
but haven’t figured out how to allow it to capture two indices at a time.
>Solution :
You could use enumerate, then filter the index mathematically:
[v for i, v in enumerate(num_list) if i % 4 < 2]