0

I am making progress learning Python. and English. I understands tuples, lists and dictionaries, but sets don't make muchly sense. Why use a set? What is a set good for?

4
Contributors
5
Replies
6
Views
11 Years
Discussion Span
Last Post by bumsfeld
0

Thank you mawe,

so when I take the list with duplicates and make it one set then the duplicates are gone. How can I find out which were those duplicates?

1

Thank you mawe,

so when I take the list with duplicates and make it one set then the duplicates are gone. How can I find out which were those duplicates?

you can use the list method somelist.count(x),
which returns the number of i's for which somelist == x :

l=list('a list of characterstrings')
for item in set(l):
	print item,'counted',l.count(item),'times'

gives

a counted 3 times
  counted 3 times
c counted 2 times
e counted 1 times
...
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.