Perhaps you are wondering why the order is different? That is because the result from Union
is always sorted. From the documentation
Union[list] gives a sorted version of a list, in which all duplicated
elements have been dropped.
If you want to delete duplicates without changing the order then use DeleteDuplicates
. From the documentation
DeleteDuplicates never reorders elements, but only removes them.