Deleting duplicates only if they are a certain kind of duplicate
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
I have a list of tuples like this:
1,a,b,1,1,b,1,a,a,b,a,1,b,a,b
I would like to find a way to delete all those tuples in the list that contain a duplicate unless that duplicate is a 1
. Therefore, the desired result given the example input above would be:
1,a,b,1,1,b,b,a,1
I will also need to delete duplicate elements within the list (irrespective of sorting) but that is easily done (i.e. only keep one of 1,a,b
and b,a,1
).
I would like it to work for generic length tuples too, for example:
1,1,1,1,1,a,a,b,a,b,b,c,1,a,b,c,1,1,a,b
would become
1,1,1,1,1,a,b,c,1,1,a,b
list-manipulation filtering
add a comment |Â
up vote
3
down vote
favorite
I have a list of tuples like this:
1,a,b,1,1,b,1,a,a,b,a,1,b,a,b
I would like to find a way to delete all those tuples in the list that contain a duplicate unless that duplicate is a 1
. Therefore, the desired result given the example input above would be:
1,a,b,1,1,b,b,a,1
I will also need to delete duplicate elements within the list (irrespective of sorting) but that is easily done (i.e. only keep one of 1,a,b
and b,a,1
).
I would like it to work for generic length tuples too, for example:
1,1,1,1,1,a,a,b,a,b,b,c,1,a,b,c,1,1,a,b
would become
1,1,1,1,1,a,b,c,1,1,a,b
list-manipulation filtering
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I have a list of tuples like this:
1,a,b,1,1,b,1,a,a,b,a,1,b,a,b
I would like to find a way to delete all those tuples in the list that contain a duplicate unless that duplicate is a 1
. Therefore, the desired result given the example input above would be:
1,a,b,1,1,b,b,a,1
I will also need to delete duplicate elements within the list (irrespective of sorting) but that is easily done (i.e. only keep one of 1,a,b
and b,a,1
).
I would like it to work for generic length tuples too, for example:
1,1,1,1,1,a,a,b,a,b,b,c,1,a,b,c,1,1,a,b
would become
1,1,1,1,1,a,b,c,1,1,a,b
list-manipulation filtering
I have a list of tuples like this:
1,a,b,1,1,b,1,a,a,b,a,1,b,a,b
I would like to find a way to delete all those tuples in the list that contain a duplicate unless that duplicate is a 1
. Therefore, the desired result given the example input above would be:
1,a,b,1,1,b,b,a,1
I will also need to delete duplicate elements within the list (irrespective of sorting) but that is easily done (i.e. only keep one of 1,a,b
and b,a,1
).
I would like it to work for generic length tuples too, for example:
1,1,1,1,1,a,a,b,a,b,b,c,1,a,b,c,1,1,a,b
would become
1,1,1,1,1,a,b,c,1,1,a,b
list-manipulation filtering
list-manipulation filtering
edited 7 mins ago
J. M. is computer-less♦
94.8k10294454
94.8k10294454
asked 25 mins ago


Daniel Wilson-Nunn
1995
1995
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
4
down vote
list = 1, a, b, 1, 1, b, 1, a, a, b, a, 1, b, a, b;
l1 = Select[list,DuplicateFreeQ[DeleteCases[#,1]]&]
1, a, b, 1, 1, b, b, a, 1
DeleteDuplicatesBy[Sort]@l1
1, a, b, 1, 1, b
list2 = 1, 1, 1, 1, 1, a, a, b, a, b, b, c, 1, a, b, c, 1, 1, a, b;
l2 = Select[list2, DuplicateFreeQ[DeleteCases[#, 1]] &]
1, 1, 1, 1, 1, a, b, c, 1, 1, a, b
DeleteDuplicatesBy[Sort]@l2
1, 1, 1, 1, 1, a, b, c, 1, 1, a, b
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
list = 1, a, b, 1, 1, b, 1, a, a, b, a, 1, b, a, b;
l1 = Select[list,DuplicateFreeQ[DeleteCases[#,1]]&]
1, a, b, 1, 1, b, b, a, 1
DeleteDuplicatesBy[Sort]@l1
1, a, b, 1, 1, b
list2 = 1, 1, 1, 1, 1, a, a, b, a, b, b, c, 1, a, b, c, 1, 1, a, b;
l2 = Select[list2, DuplicateFreeQ[DeleteCases[#, 1]] &]
1, 1, 1, 1, 1, a, b, c, 1, 1, a, b
DeleteDuplicatesBy[Sort]@l2
1, 1, 1, 1, 1, a, b, c, 1, 1, a, b
add a comment |Â
up vote
4
down vote
list = 1, a, b, 1, 1, b, 1, a, a, b, a, 1, b, a, b;
l1 = Select[list,DuplicateFreeQ[DeleteCases[#,1]]&]
1, a, b, 1, 1, b, b, a, 1
DeleteDuplicatesBy[Sort]@l1
1, a, b, 1, 1, b
list2 = 1, 1, 1, 1, 1, a, a, b, a, b, b, c, 1, a, b, c, 1, 1, a, b;
l2 = Select[list2, DuplicateFreeQ[DeleteCases[#, 1]] &]
1, 1, 1, 1, 1, a, b, c, 1, 1, a, b
DeleteDuplicatesBy[Sort]@l2
1, 1, 1, 1, 1, a, b, c, 1, 1, a, b
add a comment |Â
up vote
4
down vote
up vote
4
down vote
list = 1, a, b, 1, 1, b, 1, a, a, b, a, 1, b, a, b;
l1 = Select[list,DuplicateFreeQ[DeleteCases[#,1]]&]
1, a, b, 1, 1, b, b, a, 1
DeleteDuplicatesBy[Sort]@l1
1, a, b, 1, 1, b
list2 = 1, 1, 1, 1, 1, a, a, b, a, b, b, c, 1, a, b, c, 1, 1, a, b;
l2 = Select[list2, DuplicateFreeQ[DeleteCases[#, 1]] &]
1, 1, 1, 1, 1, a, b, c, 1, 1, a, b
DeleteDuplicatesBy[Sort]@l2
1, 1, 1, 1, 1, a, b, c, 1, 1, a, b
list = 1, a, b, 1, 1, b, 1, a, a, b, a, 1, b, a, b;
l1 = Select[list,DuplicateFreeQ[DeleteCases[#,1]]&]
1, a, b, 1, 1, b, b, a, 1
DeleteDuplicatesBy[Sort]@l1
1, a, b, 1, 1, b
list2 = 1, 1, 1, 1, 1, a, a, b, a, b, b, c, 1, a, b, c, 1, 1, a, b;
l2 = Select[list2, DuplicateFreeQ[DeleteCases[#, 1]] &]
1, 1, 1, 1, 1, a, b, c, 1, 1, a, b
DeleteDuplicatesBy[Sort]@l2
1, 1, 1, 1, 1, a, b, c, 1, 1, a, b
edited 15 mins ago
answered 21 mins ago
kglr
166k8188388
166k8188388
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f184084%2fdeleting-duplicates-only-if-they-are-a-certain-kind-of-duplicate%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password