How can I remove B -> A from a list if A -> B is in the list?
If you do not mind changing your edge directions and order, as J.M.'s answer does, this can be done much more simply since Sort
works on arbitrary expressions:
Union[Sort /@ rules]
If you do not want to change the directions or order, you can use this:
First /@ GatherBy[rules, Sort]
Mathematica 10 introduced DeleteDuplicatesBy
which may also be used:
DeleteDuplicatesBy[list, Sort]
{"A" -> "B", "C" -> "D"}
This seems to do what you want:
rules = {"A" -> "B", "B" -> "A", "C" -> "D"};
Rule @@@ Union[Composition[Sort, List] @@@ rules]
(* {"A" -> "B", "C" -> "D"} *)
Using Mathematica 7
Needs["GraphUtilities`"];
Rule @@@ DeleteDuplicates[Sort /@ EdgeList[list]]
giving
{"A" -> "B", "C" -> "D"}