If the order of i and j does not matter (or if you want them sorted), then the following will work:
DeleteDuplicates@ Block[{Rule},
SetAttributes[Rule, Orderless];
{1 -> 4, 4 -> 1, 2 -> 3, 3 -> 2}
]
(* {1 -> 4, 2 -> 3} *)
l = {{1 -> 4, 3, 0}, {4 -> 1, 4, 0}, {3 -> 2, 9, 0}, {2 -> 3, 1, 0}};
DeleteDuplicatesBy[First]@ Block[{Rule},
SetAttributes[Rule, Orderless];
l
]
(* {{1 -> 4, 3, 0}, {2 -> 3, 9, 0}} *)
It's probably important that only the list l is evaluated inside the Block. One probably does not want to evaluate any built-in functions while Rule is Orderless.
The method above is pretty fast. Some timings:
SeedRandom[0];
ll = Rule @@@ RandomInteger[200, {100000, 2}];
DeleteDuplicates@Block[{Rule}, SetAttributes[Rule, Orderless]; ll] // Length // AbsoluteTiming
DeleteDuplicatesBy[Sort]@ll // Length // AbsoluteTiming
Values[GroupBy[ll, Sort, First]] // Length // AbsoluteTiming
(*
{0.084336, 20152} M e2
{0.17234, 20152} kglr
{0.178762, 20152} ubpdqn
*)
The two-argument DeleteDuplicates[ll, # == Reverse@#2 &], as ciao remarks in a comment, will be a bit slower as the list grow in size (because it uses pairwise comparison that is of quadratic complexity); it takes 0.18 sec. on a list of only 750 rules. Sascha's takes 3+ sec. on the input ll = Rule @@@ RandomInteger[15, {150, 2}], but it is interesting for other reasons.
{4 -> 1, 3 -> 2}and not{1 -> 4, 2 -> 3}? – Nasser Sep 10 '16 at 07:38DeleteDuplicates[list, # == Reverse@#2 &]is the simple way. If list is huge, faster ways to do it... – ciao Sep 10 '16 at 07:40DeleteDuplicates[l, #[[1]] == Reverse@#2[[1]] &]thank you @ciao – Conor Sep 10 '16 at 08:26SimpleGraph. – Szabolcs Sep 10 '16 at 17:20