Formula for extracting certain elements from a list
I need a formula to iterate through list A and extract certain items and put into list B. I need to skip two items, extract the next three, skip two items, extract the next three, etc:
Code:
A = (34, 35, 40, 41, 42, 22, 34, 43, 44, 45, 65, 78, 46, 47, 48)
I want:
Code:
B = (40, 41, 42, 43, 44, 45, 46, 47, 48)
this is all I could get:
Code:
for i, val in enumerate(A):
B = (
thanks
Re: Formula for extracting certain elements from a list
In pseudocode, assuming "i" is the index of the item in the list and i starts at 0:
Code:
if i % 5 < 2, skip
else extract
You should be able to do that in python. "%" is the "remainder" operator - it divides the left side by the right side and returns the remainder. If it isn't the same in python, I am sure there is a similar operator or function that does the same.