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
Featured Replies
  • Hi! Did you have a look at the [url=http://www.python.org/doc/2.4.2/tut/node7.html#SECTION007400000000000000000]python-docs[/url]? This should make clear that sets are really useful :) Regards, mawe Read More

  • [QUOTE=bumsfeld]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?[/QUOTE] you can use the list method somelist.count(x), which returns the number of i's for which somelist[i] == x : [CODE] … Read More

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.
Take the time to help us to help you. Please be thoughtful and detailed and be sure to adhere to our posting rules.