I have a list:
{{Subscript[i, 1], Subscript[a, 1], Subscript[b, 1]},
{Subscript[i, 1], Subscript[a, 2], Subscript[b, 2]},
...,
{Subscript[i, r], Subscript[b, 1], Subscript[a, 1]},
...,
{Subscript[i, s], Subscript[b, 2], Subscript[a, 2]},
...,
{Subscript[i, n], Subscript[a, n], Subscript[b, n]}
}
in other words; this is a list indexed by:
{Subscript[i, 1], Subscript[i, 2], ..., Subscript[i, n]}
and every now and then; there are instances in the list where:
{Subscript[a, i], Subscript[b, i]}
is considered the same as:
{Subscript[b, i], Subscript[a, i]}
.
For example; if two jobs contained in the above list; namely,
{"Bill and Account Collectors", "Ticket Agents and Travel Clerks"}
have a job relational score of 0.5; then
{"Ticket Agents and Travel Clerks", "Bill and Account Collectors"}
also have the same relational score.
My question is; how can I collapse the above list to get a new list so that; if
{Subscript[a, i], Subscript[b, i]} == {Subscript[b, i], Subscript[a, i]}
then only
{Subscript[i, s], {Subscript[a, i], Subscript[b, i]}}
is included in my new list; and if:
{Subscript[a, k], Subscript[b, k]} not equal {Subscript[b, k], Subscript[a, k]}
then both:
{Subscript[i, s], {Subscript[a, k], Subscript[b, k]}}
and
{Subscript[i, t], {Subscript[a, k], Subscript[b, k]}}
are also included in my new list?
As an example, if
IndexedSOCList = {{1., 431011., 431011.}, {2., 431011., 433011.}, {3., 433011., 431011.},
{4., 431011., 433021.}, {5., 433021., 431011.}, {6., 431011., 433031.},
{7., 433031., 431011.}, {8., 431011., 433051.}, {9., 433051., 431011.},
{10., 431011., 433061.}, {11., 433061., 431011.}, {12., 431011., 433071.},
{13., 433071., 431011.}, {14., 431011., 434011.}, {15., 434011., 431011.},
{16., 431011., 434031.}, {17., 434031., 431011.}, {18., 431011., 434041.},
{19., 434041., 431011.}};
then the desired output is
(* {{1., 431011., 431011.}, {2., 431011., 433011.}, {4., 431011., 433021.},
{6., 431011., 433031.}, {8., 431011., 433051.}, {10., 431011., 433061.},
{12., 431011., 433071.}, {14., 431011., 434011.}, {16., 431011., 434031.},
{18., 431011., 434041.}} *)
Union[list, SameTest -> (Sort[#1[[2]]] === Sort[#2[[2]]] &)]
. $\endgroup$IndexedSOCList={{1., {431011., 431011.}}, {2., {431011., 433011.}}, {3., {433011., 431011.}}, ...
, in which case my code works (if I understood what you were after, of course). If the format in your comment is the actual correct one, then tryUnion[IndexedSOCList, SameTest -> (Sort[#1[[2 ;; 3]]] === Sort[#2[[2 ;; 3]]] &)]
. $\endgroup$