# Delete duplicates element sublist

I'm wondering if this is possible to delete duplicate elements if a=b and b=a using deleteduplicates or any simple way.

l1 = {{284, 220}, {220, 284}, {1210, 1184}, {1184, 1210}, {2924,
2620}, {2620, 2924}, {5564, 5020}, {5020, 5564}, {6368,
6232}, {6232, 6368}, {10856, 10744}, {10744, 10856}, {14595, 12285}}

DeleteDuplicatesBy[
l1], First == Last && Last==First]


For exemple, I would like to delete {284,220}, {1210,1184}, ...

Thank you

• l1 // DeleteDuplicatesBy[Sort] Dec 15, 2022 at 14:33

## 4 Answers

Try this:

DeleteDuplicates[Sort /@ l1]
(*{{220, 284}, {1184, 1210}, {2620, 2924}, {5020, 5564}, {6232, 6368}, {10744, 10856}, {12285, 14595}}*)

• It's a (+1) from me. Just as a comment one could use Union, i.e DeleteDuplicates[Union /@ l1]
– bmf
Dec 15, 2022 at 1:29
• Hi, friend! I'm glad to see you here. I hope everything went well with your move. You're right, it works great with Union. Dec 15, 2022 at 1:32
• Hello.. Still trying to figure out some stuff, but it's getting better on a daily basis, thanks! Hope you're also well :-)
– bmf
Dec 15, 2022 at 1:33
• I'm coming out of a flu, but everything is going well so far, thanks! :-) Dec 15, 2022 at 1:36
• Thank you! I can't believe I didn't think of it. Dec 15, 2022 at 1:48

Ok, since @E. Chan-López gave the proper answer let's see with what else we can come up.

Suggested solution

Gather[Sort /@ l1][[All, 1]]

Comparison with the DeleteDuplicates solution

DeleteDuplicates[Sort /@ l1] - Gather[Sort /@ l1][[All, 1]]

{{0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}}

l1 = {{284, 220}, {220, 284}, {1210, 1184}, {1184, 1210}, {2924,
2620}, {2620, 2924}, {5564, 5020}, {5020, 5564}, {6368,
6232}, {6232, 6368}, {10856, 10744}, {10744, 10856}, {14595,
12285}};

ConnectedComponents[Graph[UndirectedEdge @@@ l1]]

{{5020, 5564}, {6368, 6232}, {14595, 12285}, {2620, 2924}, {220,
284}, {10856, 10744}, {1184, 1210}}

list = {{12, 10}, {10, 12}, {20, 20}, {20, 20}, {16, 15}, {12, 10}};


I would suggest

DeleteDuplicatesBy[SymmetricDifference] @ list


{{12, 10}, {20, 20}, {16, 15}}

because it doesn't sort the sublists. "Why should the unpaired {16, 15} become {15, 16}"? one could ask pedantically.

Compare with the accepted answer:

DeleteDuplicates[Sort /@ list]


{{10, 12}, {20, 20}, {15, 16}}

SymmetricDifference came with V 13.1.

• (+1) An important point IMO. Sep 26 at 18:19