I would like to remove the numbers from the list of three in three positions and then store them in a new list. I thought of doing something like n+3 but don´t know how to implement it.
[1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 1, 6, 1, 4, 7, 2, 4, 8, 4, 6, 9, 6, 5]
This is my list and I would like to create a new list like this:
[1,2,3,4,5,6,7,8,9]
Thank you in advance
>Solution :
As far as I understand, you want to pick one element in every three elements. For that, you can use slicing [::3], where 3 means the step size:
lst = [1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 1, 6, 1, 4, 7, 2, 4, 8, 4, 6, 9, 6, 5]
output = lst[::3]
print(output) # [1, 2, 3, 4, 5, 6, 7, 8, 9]