# Thread: Formula for extracting certain elements from a list

1. Novice
Join Date
Jan 2017
Posts
54
Thanks
8
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:
`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:
`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:
`for i, val in enumerate(A):    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:
`if i % 5 < 2, skipelse 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)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.