# Thread: Formula for extracting certain elements from a list

1. Novice
Join Date
Jan 2017
Posts
24
Thanks
2
Qt products
Platforms

## 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:

Qt Code:
1. A = (34, 35, 40, 41, 42, 22, 34, 43, 44, 45, 65, 78, 46, 47, 48)
To copy to clipboard, switch view to plain text mode

I want:
Qt Code:
1. B = (40, 41, 42, 43, 44, 45, 46, 47, 48)
To copy to clipboard, switch view to plain text mode

this is all I could get:
Qt Code:
1. for i, val in enumerate(A):
2. B = (
To copy to clipboard, switch view to plain text mode

thanks

2. ## 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:

Qt Code:
1. if i % 5 < 2, skip
2. else extract
To copy to clipboard, switch view to plain text mode

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.

3. ## The following user says thank you to d_stranz for this useful post:

dennisvz (20th July 2019)