1

If I have a set of items in a list say:

MyList = ["a", "b", "c", "c", "b"]

And I want to get the count of the total number of unique items (in this case 3)

I figure it needs to be some variant on len(myList) but I'm not sure how to eliminate the duplicates?

Mike
  • 785
  • 1
  • 13
  • 29
  • I'm not sure how to answer the part about it being duplicate... it's true, but for some reason I didn't find it with a google search, and I think my version of the question is a bit clearer (but I'm ok with this being deleted if need be as I got my answer) – Mike Mar 15 '15 at 20:44

1 Answers1

6

You can convert your list to a set which is guaranteed to have unique items:

MyList = ["a", "b", "c", "c", "b"]
print len(set(MyList))

result:

3
Selcuk
  • 57,004
  • 12
  • 102
  • 110