Grouping by Split, apply, combine

@Optimization, please check annotated code below, where the input was sligthly modified to try removing some ambiguity in the problem statement.

using SplitApplyCombine

A = [(1,5,2,5), (11,5,9,6), (7,5,2,6), (11,5,2,5), (8,5,9,6), (3,5,3,6), (7,5,9,6), (1,5,3,6)]
D = group(t -> t[3], A)  # groups tuples by their 3rd element
b = (11, 8, 3)    # tuple for filtering the last 3 groups computed, one value per group

[k => filter(x -> x[1] == v, d) for (v, (k,d)) in zip(b, pairs(D))]  # matches first element of each tuple

3-element Vector{Pair{Int64, Vector{NTuple{4, Int64}}}}:
 2 => [(11, 5, 2, 5)]
 9 => [(8, 5, 9, 6)]
 3 => [(3, 5, 3, 6)]
1 Like