It might be that you're slightly misunderstanding what Union
does. It finds the union of the elements of the list that is passed to it, but it doesn't dig into lists within that list. So when you write Union[{{a,d},{a,d}}]
, the function sees a list with two elements, {a,d}
(that's element 1) and {a,d}
(that's element 2). They are the same, so it removes the duplicate and returns just {a,d}
. But when you write Union[{{a,d},{d,a}}]
, it sees a list with two different elements: {a,d}
(that's element 1) and {d,a}
(that's element 2). The fact that those two lists contain the same items is irrelevant; they're not equal, according to an ordered element-by-element comparison, so Union
has no duplicates to remove.
Now, it seems like what you're trying to do is get all lists which are distinct in terms of their content, irrespective of order - in other words, you're treating the lists as mathematical sets. I think Union[Sort/@lsts]
should be a fine way to go, because that's the standard method of comparing sets for equality when you don't have an actual unordered set type. (If Mathematica does, I don't know about it.)
Union @@ lsts
? $\endgroup$