List contains only integers. I need to select elements with the next requirements (every requirement is a separate problem):
Elements between 1 and 1:
[2,1,3,1,3] -> [3],[2,1,3,4,1,3] -> [3,4]Elements between same numbers: a) only one pair of same number is allowed:
[1,2,3,2] -> [3] (2 and 2), [1,4,3,5,4] -> [3,5], (4 and 4)b) multiple pairs is allowed:[1,2,1,2] -> [[2],[1]], (pairs of: (1,1),(2,2)); [1,4,3,5,4,3,2] -> [[3,5],[5,4], (pairs of: (4,4), (3,3))Elements that have more than one same neighborhood:
[1,1,3] -> [1,1], (2 consecutive 1s), [1,1,3,2,2,2,1] -> [1,1,2,2,2] (2 consecutive 1s and 3 consecutive 2s)
What is general approach to this problem? I have worked with filter but only with one parameter predicate: filter(lambda x: (x%2 == 0), numbers)
Is there another approach rather than nested for loops? Maybe more functional style. Is it possible to use convolutions as a solution?