Selecting elements from a list under multiple conditions
In this case, a slightly more intricate approach using Counts[]
is useful:
Select[(And @@ Thread[Lookup[Counts[#], {1, 2, 3}, 0] <= {3, 3, 1}]) &] /@ l
{{{3, 2, 2, 2, 1, 1}}, {{3, 2, 2, 2, 1, 1, 1}}}
Pick[l, Map[Count[#, 3] < 2 && Count[#, 2] < 4 && Count[#, 1] < 4 &,
l, {2}]]
{{{3, 2, 2, 2, 1, 1}}, {{3, 2, 2, 2, 1, 1, 1}}}
Pick[l, Map[VectorLessEqual[{BinCounts[#, {1/2, 3 + 1/2, 1}] , {3, 3, 1} }]&, l, {-2}] ]
{{{3, 2, 2, 2, 1, 1}}, {{3, 2, 2, 2, 1, 1, 1}}}