-3

I have the following Lists: I need to check if it has duplicates we assume (['f', 't'] = ['t', 'f']) (order of elements in the list does not matter) and hence this should return 'duplicate' as it has both the lists

['f', 't']
['f', 'r']
['t', 'f']
['f', 'u']
['b', 't']
['b', 'r']
['b', 'l']
['b', 'u']
['r', 't']
['r', 'u']
['l', 't']
['l', 'u']

and I did try to run an iteration to check if any duplicate lists but it fails as each element is compared to itself in the iteration one time. Any leads to the same will be appreciated

Prabhanjan
  • 155
  • 2
  • 10

1 Answers1

0

Try this:

duplicate_list = [['f', 't'],
['f', 'r'],
['t', 'f'],
['f', 'u'],
['b', 't'],
['b', 'r'],
['b', 'l'],
['b', 'u'],
['r', 't'],
['r', 'u'],
['l', 't'],
['l', 'u']]

seen = set()
for el in duplicate_list:
    el = frozenset(el)
    if el in seen:
        print("Duplicate")
        break
    seen.add(el)
Kamil Niski
  • 4,580
  • 1
  • 11
  • 24