(Gather /@ {{1, 1, 1, 1, 2}, {2, 2, 2, 2, 3}, {3, 3, 3, 4,
3}, {8, 8, 7, 8, 8}})[[All, 1]]
(* {{1, 1, 1, 1}, {2, 2, 2, 2}, {3, 3, 3, 3}, {8, 8, 8, 8}} *)
Will work so long as the element you want to keep is first in the list, but it fails here
(Gather /@ {{1, 1, 1, 1, 2}, {2, 2, 2, 2, 3}, {3, 3, 3, 4,
3}, {8, 8, 7, 8, 8}, {4, 9, 9, 9, 9}})[[All, 1]]
(* {{1, 1, 1, 1}, {2, 2, 2, 2}, {3, 3, 3, 3}, {8, 8, 8, 8}, {4}} *)
So first use Gather
, then sort by Length
, so that you are choosing the list with the most number of elements.
This function does the trick
removeoddelement[list_] := Last@SortBy[Gather[list], Length]
removeoddelement@{11, 11, 90, 11, 11}
(* {11, 11, 11, 11} *)
removeoddelement /@ {{192, 12, 12, 12, 12}, {118, 0, 0, 0,
0}, {2, 2, 2, 165, 2}, {3, 3, 3, 3, 112}, {113, 14, 14, 14,
14}, {14, 91, 14, 14, 14}, {5, 5, 5, 5, 150}, {6, 6, 6, 186,
6}, {5, 5, 5, 108, 5}, {15, 15, 15, 151, 15}, {10, 10, 10, 76,
10}, {3, 3, 3, 174, 3}, {14, 162, 14, 14, 14}, {7, 139, 7, 7,
7}, {4, 4, 73, 4, 4}, {115, 14, 14, 14, 14}, {135, 10, 10, 10,
10}, {1, 1, 1, 119, 1}, {7, 165, 7, 7, 7}, {5, 5, 149, 5, 5}}
(* {{12, 12, 12, 12}, {0, 0, 0, 0}, {2, 2, 2, 2}, {3, 3, 3,
3}, {14, 14, 14, 14}, {14, 14, 14, 14}, {5, 5, 5, 5}, {6, 6, 6,
6}, {5, 5, 5, 5}, {15, 15, 15, 15}, {10, 10, 10, 10}, {3, 3, 3,
3}, {14, 14, 14, 14}, {7, 7, 7, 7}, {4, 4, 4, 4}, {14, 14, 14,
14}, {10, 10, 10, 10}, {1, 1, 1, 1}, {7, 7, 7, 7}, {5, 5, 5, 5}} *)