Python | Unique pairs in the list

Counters | Python Methods and Functions

Method: Using frozenset () + Counter () + list comprehension
A combination of the above functions can accomplish this task. The frozenset () function is used to ignore order, Counter () is used to perform the uniqueness check task, and iteration is performed using a list.

# Python3 code to demonstrate how it works
# Unique pairs in the list
# using frozenset () + Counter () + comprehension list

from collections import Counter

 
# initialize the list

test_list = [[ 5 , 6 ], [ 9 , 8 ], [ 8 , 9 ], [ 1 , 4 ], [ 6 , 5 ], [ 10 , 1 ]]

 
# print original list

print ( "The original list is:" + str (test_list))

 
# Unique pairs in the list
# using frozenset () + Counter () + comprehension list

temp = Counter ( frozenset (ele) for ele in test_list)

res = [temp [ frozenset (ele)] = = 1 for ele in test_list]

  
# print result

print ( "The Unique status of elements is" + str (res))

Output:

 The original list is: [[5, 6], [9, 8], [8, 9], [1, 4], [6, 5] ], [10, 1]] The Unique status of elements is [False, False, False, True, False, True] 




Get Solution for free from DataCamp guru