python - Find unique pairs in list of pairs -


i have (large) list of lists of integers, e.g.,

a = [     [1, 2],     [3, 6],     [2, 1],     [3, 5],     [3, 6]     ] 

most of pairs appear twice, order of integers doesn't matter (i.e., [1, 2] equivalent [2, 1]). i'd find pairs appear once, , boolean list indicating that. above example,

b = [false, false, false, true, false] 

since a typically large, i'd avoid explicit loops. mapping frozensets may advised, i'm not sure if that's overkill.

ctr = counter(frozenset(x) x in a) b = [ctr[frozenset(x)] == 1 x in a] 

we can use counter counts of each list (turn list frozenset ignore order) , each list check if appears once.


Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -