5

Possible Duplicate:
How can I remove B -> A from a list if A -> B is in the list?

I'm working toward building a graph and use some code to construct my rules which results in a form as follows:

g = {1 -> 2, 1 -> 3, 2 -> 1, 2 -> 3, 2 -> 4, 3 -> 2, 3 -> 4, 3 -> 1, 4 -> 3, 4 -> 2}

I would like to delete all reverse duplicate entries form the list, i.e. both 1->2 and 2->1 appear in the list. I would like to get rid of one of them and do this for all reverse duplicates in the list g.

johntfoster
  • 393
  • 1
  • 7
  • All: please try a bit harder to find duplicate questions; thank you. – Mr.Wizard Jun 27 '12 at 20:46
  • @Tom That case is already covered by my own answer to the previous question. If you feel that this closure was in error feel free to vote to reopen. IMHO the fact that identical answers were posted indicates it is a true duplicate. (ps. please use the @name notification when responding; I didn't see your message until now.) – Mr.Wizard Jun 28 '12 at 07:10

2 Answers2

5

Union[Sort /@ g] seems to be what you need...

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
4

This satisfies your needs

DeleteDuplicates @ (Sort /@ g)
{1 -> 2, 1 -> 3, 2 -> 3, 2 -> 4, 3 -> 4}
Artes
  • 57,212
  • 12
  • 157
  • 245