Issue
I have a array, I want to pick first 2 or range, skip the next 2, pick the next 2 and continue this until the end of the list
list = [2, 4, 6, 7, 9,10, 13, 11, 12,2]
results_wanted = [2,4,9,10,12,2] # note how it skipping 2. 2 is used here as and example
Is there way to achieve this in python?
Solution
Taking n
number of elements and skipping the next n
.
l = [2, 4, 6, 7, 9, 10, 13, 11, 12, 2]
n = 2
wanted = [x for i in range(0, len(l), n + n) for x in l[i: i + n]]
### Output : [2, 4, 9, 10, 12, 2]
Answered By - Vikrant Sharma
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.