In this case if two lists with the same total then one list is deleted. Can I add one more condition to choose which one to be deleted, for example the deleted list between the two is the one where sum of the first three elements of the list is larger than 0?
list = {{0, 1, 0, 0, 0}, {1, 0, 1, 0, 1}, {1, 1, 1, 0, 0}, {0, 0, 0,
0, 1}, {1, 1, 1, 0, 1}};
DeleteDuplicates[list, Total[#1] == Total[#2] &]
EDIT: This is the whole problem actually I'm trying to solve. I have tup1
and I removed some elements to get tup2
like below. However, now I want to add one more condition for which one to deleted from the pair. The list1
from the pair is deleted if Total[#1[[1 ;; 3]]]< Total[#2[[1 ;; 3]]]
.
tup1 = Tuples@{{-1, 0, 1}, {-1, 0, 1}, {-1, 0, 1}, {-1, 0, 1}, {-1, 0,
1}, {-1, 0, 1}};
tup2 = DeleteDuplicates[
tup1, (#1[[1 ;; 3]] == #2[[4 ;; 6]]) && (#1[[4 ;; 6]] == #2[[1 ;;
3]]) || (#1 == -#2) &];
chooseTheRightOne /@ GatherBy[list, Total]
? $\endgroup$DeleteDuplicates
because I have a code needs to use that? $\endgroup$DeleteDuplicates
only removes identical elements, under some condition. It does not have a mechanism to make further choices on which element to delete, so it is not the appropriate approach for your problem. You can still use it to obtaintup2
(although answers to your previous question suggested much faster approaches for that too), but then you will have to further work ontup2
, for example in the way I showed below, to get the final result. $\endgroup$