0

I have a big list of strings appearing many times and I want a list of the same strings to appear only once.

An example with numbers would be:

a = [1, 2, 2, 3, 4, 4]

and I want to get

b = [1, 2, 3, 4]

What I tried is something like:

a = [1, 2, 2, 3, 4, 4]
[x for x in a if a.count(x) == 1]
[1, 3]

but this omits the duplicate numbers and takes only those appearing once.

hpaulj
  • 221,503
  • 14
  • 230
  • 353

1 Answers1

1

You can try this:

import collections
a = [1, 2, 2, 2, 3, 3, 4, 4, 5, 6, 7, 7, 8]
print([item for item, count in collections.Counter(a).items()])
Imtiyaz Shaikh
  • 425
  • 3
  • 7