0

I am trying to remove any elements from a list that has a duplication.

The example that I am trying to achieve is:

a, b, c d, g, h, i, d, c, b, a

would reduce down to: g, h, i

I have found a lot of great ways to remove duplications but I haven't come across a way to remove elements if a duplication exists. Thanks for any assistance

1 Answers1

0

You can do that using collections

import collections
a_list = ['a','b','c','d','g','h','i','d','c','b','a']
counter = collections.Counter(a_list)

a_list_final = [key for key,value in counter.items() if value == 1]
print(a_list_final)
    ['h', 'g', 'i']
cph_sto
  • 7,189
  • 12
  • 42
  • 78