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?

Recommended Answers

All 5 Replies

Hi!

Did you have a look at the python-docs?
This should make clear that sets are really useful :)

Regards, mawe

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?

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
...

Thanks from the rest of us monkeyy! Great code!

Yes, thanks monkeyy!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.