Skip to main content
edited body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
ClearAll[f1, f2, f3]
f1 = Cases[{___, {Except[a_]..., a_, Except[a_]...}, ___}]@*Cases[{___, {(a_)..}, ___}];
f1f2 = Select[MemberQ[Tally /@ #, {_, 1}, All] &]@*Cases[{___, {(a_)..}, ___}] ;
f2f3 = Pick[#, MemberQ[#, {_, 1}, All]& /@ Map[Tally, #, {2}]]& @*Cases[{___, {(a_)..}, ___}];

Examples:

lst1 = {{{4}}, {{7, 7}, {7, 7}}, {{5, 5}, {6, 6}}, {{2, 1}, {1, 1}}};
f1 @ lst1

{{{4}}, {{2, 1}, {1, 1}}}

f1 @ lst1 == f2 @ lst1 == f3 @lst1

True

lst2 = {{{3, 3}, {3, 2}}, {{1, 1, 1, 1}, {1, 2, 3, 0}, {1, 0, 0, 
     0}, {1, 0, 3, 2}}, {{1, 1, 1, 1, 1}, {1, 4, 3, 0, 4}, {1, 3, 3, 
     3, 0}, {1, 0, 3, 4, 4}, {1, 4, 0, 4, 4}}} ;
f1 @ lst2 == f2 @lst2 == f3 @ lst2 == lst2

True

ClearAll[f1, f2, f3]
f1 = Cases[{___, {Except[a_]..., a_, Except[a_]...}, ___}]@*Cases[{___, {(a_)..}, ___}];
f1 = Select[MemberQ[Tally /@ #, {_, 1}, All] &]@*Cases[{___, {(a_)..}, ___}] ;
f2 = Pick[#, MemberQ[#, {_, 1}, All]& /@ Map[Tally, #, {2}]]& @*Cases[{___, {(a_)..}, ___}];

Examples:

lst1 = {{{4}}, {{7, 7}, {7, 7}}, {{5, 5}, {6, 6}}, {{2, 1}, {1, 1}}};
f1 @ lst1

{{{4}}, {{2, 1}, {1, 1}}}

f1 @ lst1 == f2 @ lst1 == f3 @lst1

True

lst2 = {{{3, 3}, {3, 2}}, {{1, 1, 1, 1}, {1, 2, 3, 0}, {1, 0, 0, 
     0}, {1, 0, 3, 2}}, {{1, 1, 1, 1, 1}, {1, 4, 3, 0, 4}, {1, 3, 3, 
     3, 0}, {1, 0, 3, 4, 4}, {1, 4, 0, 4, 4}}} ;
f1 @ lst2 == f2 @lst2 == f3 @ lst2 == lst2

True

ClearAll[f1, f2, f3]
f1 = Cases[{___, {Except[a_]..., a_, Except[a_]...}, ___}]@*Cases[{___, {(a_)..}, ___}];
f2 = Select[MemberQ[Tally /@ #, {_, 1}, All] &]@*Cases[{___, {(a_)..}, ___}] ;
f3 = Pick[#, MemberQ[#, {_, 1}, All]& /@ Map[Tally, #, {2}]]& @*Cases[{___, {(a_)..}, ___}];

Examples:

lst1 = {{{4}}, {{7, 7}, {7, 7}}, {{5, 5}, {6, 6}}, {{2, 1}, {1, 1}}};
f1 @ lst1

{{{4}}, {{2, 1}, {1, 1}}}

f1 @ lst1 == f2 @ lst1 == f3 @lst1

True

lst2 = {{{3, 3}, {3, 2}}, {{1, 1, 1, 1}, {1, 2, 3, 0}, {1, 0, 0, 
     0}, {1, 0, 3, 2}}, {{1, 1, 1, 1, 1}, {1, 4, 3, 0, 4}, {1, 3, 3, 
     3, 0}, {1, 0, 3, 4, 4}, {1, 4, 0, 4, 4}}} ;
f1 @ lst2 == f2 @lst2 == f3 @ lst2 == lst2

True

added 94 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
ClearAll[f1, f2]f2, f3]
f1 = Cases[{___, {Except[a_]..., a_, Except[a_]...}, ___}]@*Cases[{___, {(a_)..}, ___}];
f1 = Select[MemberQ[Tally /@ #, {_, 1}, All] &]@*Cases[{___, {(a_)..}, ___}] ;
f2 = Pick[#, MemberQ[#, {_, 1}, All]& /@ Map[Tally, #, {2}]]& @*Cases[{___, {(a_)..}, ___}];

Examples:

lst1 = {{{4}}, {{7, 7}, {7, 7}}, {{5, 5}, {6, 6}}, {{2, 1}, {1, 1}}};
f1 @ lst1

{{{4}}, {{2, 1}, {1, 1}}}

f1 @ lst1 == f2 @ lst1 == f3 @lst1

{{{4}}, {{2, 1}, {1, 1}}} True

lst2 = {{{3, 3}, {3, 2}}, {{1, 1, 1, 1}, {1, 2, 3, 0}, {1, 0, 0, 
     0}, {1, 0, 3, 2}}, {{1, 1, 1, 1, 1}, {1, 4, 3, 0, 4}, {1, 3, 3, 
     3, 0}, {1, 0, 3, 4, 4}, {1, 4, 0, 4, 4}}} ;
f1 @ lst2 == f2 @lst2 ==lst2== f3 @ lst2 == lst2

True

ClearAll[f1, f2]
f1 = Select[MemberQ[Tally /@ #, {_, 1}, All] &]@*Cases[{___,{(a_)..},___}] ;
f2 = Pick[#, MemberQ[#, {_, 1}, All]& /@ Map[Tally, #, {2}]]& @*Cases[{___,{(a_)..},___}];

Examples:

lst1 = {{{4}}, {{7, 7}, {7, 7}}, {{5, 5}, {6, 6}}, {{2, 1}, {1, 1}}};
f1 @ lst1

{{{4}}, {{2, 1}, {1, 1}}}

f2 @ lst1

{{{4}}, {{2, 1}, {1, 1}}}

lst2 = {{{3, 3}, {3, 2}}, {{1, 1, 1, 1}, {1, 2, 3, 0}, {1, 0, 0, 
     0}, {1, 0, 3, 2}}, {{1, 1, 1, 1, 1}, {1, 4, 3, 0, 4}, {1, 3, 3, 
     3, 0}, {1, 0, 3, 4, 4}, {1, 4, 0, 4, 4}}} ;
f1 @ lst2 == f2 @lst2 ==lst2

True

ClearAll[f1, f2, f3]
f1 = Cases[{___, {Except[a_]..., a_, Except[a_]...}, ___}]@*Cases[{___, {(a_)..}, ___}];
f1 = Select[MemberQ[Tally /@ #, {_, 1}, All] &]@*Cases[{___, {(a_)..}, ___}] ;
f2 = Pick[#, MemberQ[#, {_, 1}, All]& /@ Map[Tally, #, {2}]]& @*Cases[{___, {(a_)..}, ___}];

Examples:

lst1 = {{{4}}, {{7, 7}, {7, 7}}, {{5, 5}, {6, 6}}, {{2, 1}, {1, 1}}};
f1 @ lst1

{{{4}}, {{2, 1}, {1, 1}}}

f1 @ lst1 == f2 @ lst1 == f3 @lst1

True

lst2 = {{{3, 3}, {3, 2}}, {{1, 1, 1, 1}, {1, 2, 3, 0}, {1, 0, 0, 
     0}, {1, 0, 3, 2}}, {{1, 1, 1, 1, 1}, {1, 4, 3, 0, 4}, {1, 3, 3, 
     3, 0}, {1, 0, 3, 4, 4}, {1, 4, 0, 4, 4}}} ;
f1 @ lst2 == f2 @lst2 == f3 @ lst2 == lst2

True

deleted 1 character in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
ClearAll[f1, f2]
f1 = Select[MemberQ[Tally /@ #, {_, 1}, All] &] @*Cases[&]@*Cases[{___,{(a_)..},___}] ;
f2 = Pick[Cases[#, {___,{(a_)..},___}]Pick[#, MemberQ[#, {_, 1}, All]& /@ Map[Tally, #, {2}]]]]& &;@*Cases[{___,{(a_)..},___}];

Examples:

lst1 = {{{4}}, {{7, 7}, {7, 7}}, {{5, 5}, {6, 6}}, {{2, 1}, {1, 1}}};
f1 @ lst1

{{{4}}, {{2, 1}, {1, 1}}}

f2 @ lst1

{{{4}}, {{2, 1}, {1, 1}}}

lst2 = {{{3, 3}, {3, 2}}, {{1, 1, 1, 1}, {1, 2, 3, 0}, {1, 0, 0, 
     0}, {1, 0, 3, 2}}, {{1, 1, 1, 1, 1}, {1, 4, 3, 0, 4}, {1, 3, 3, 
     3, 0}, {1, 0, 3, 4, 4}, {1, 4, 0, 4, 4}}} ;
f1 @ lst2 == f2 @lst2 ==lst2

True

ClearAll[f1, f2]
f1 = Select[MemberQ[Tally /@ #, {_, 1}, All] &] @*Cases[{___,{(a_)..},___}] ;
f2 = Pick[Cases[#, {___,{(a_)..},___}], MemberQ[#, {_, 1}, All]& /@ Map[Tally, #, {2}]] &;

Examples:

lst1 = {{{4}}, {{7, 7}, {7, 7}}, {{5, 5}, {6, 6}}, {{2, 1}, {1, 1}}};
f1 @ lst1

{{{4}}, {{2, 1}, {1, 1}}}

f2 @ lst1

{{{4}}, {{2, 1}, {1, 1}}}

lst2 = {{{3, 3}, {3, 2}}, {{1, 1, 1, 1}, {1, 2, 3, 0}, {1, 0, 0, 
     0}, {1, 0, 3, 2}}, {{1, 1, 1, 1, 1}, {1, 4, 3, 0, 4}, {1, 3, 3, 
     3, 0}, {1, 0, 3, 4, 4}, {1, 4, 0, 4, 4}}} ;
f1 @ lst2 == f2 @lst2 ==lst2

True

ClearAll[f1, f2]
f1 = Select[MemberQ[Tally /@ #, {_, 1}, All] &]@*Cases[{___,{(a_)..},___}] ;
f2 = Pick[#, MemberQ[#, {_, 1}, All]& /@ Map[Tally, #, {2}]]& @*Cases[{___,{(a_)..},___}];

Examples:

lst1 = {{{4}}, {{7, 7}, {7, 7}}, {{5, 5}, {6, 6}}, {{2, 1}, {1, 1}}};
f1 @ lst1

{{{4}}, {{2, 1}, {1, 1}}}

f2 @ lst1

{{{4}}, {{2, 1}, {1, 1}}}

lst2 = {{{3, 3}, {3, 2}}, {{1, 1, 1, 1}, {1, 2, 3, 0}, {1, 0, 0, 
     0}, {1, 0, 3, 2}}, {{1, 1, 1, 1, 1}, {1, 4, 3, 0, 4}, {1, 3, 3, 
     3, 0}, {1, 0, 3, 4, 4}, {1, 4, 0, 4, 4}}} ;
f1 @ lst2 == f2 @lst2 ==lst2

True

added 56 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
Post Undeleted by kglr
Post Deleted by kglr
added 288 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
added 288 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
deleted 5 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
added 5 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading