944,221 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 2267
  • Python RSS
Nov 20th, 2005
0

Why a Set?

Expand Post »
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?
Similar Threads
Reputation Points: 404
Solved Threads: 180
Nearly a Posting Virtuoso
bumsfeld is offline Offline
1,422 posts
since Jul 2005
Nov 20th, 2005
1

Re: Why a Set?

Hi!

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

Regards, mawe
Reputation Points: 19
Solved Threads: 58
Junior Poster
mawe is offline Offline
133 posts
since Sep 2005
Nov 20th, 2005
0

Re: Why a Set?

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?
Reputation Points: 404
Solved Threads: 180
Nearly a Posting Virtuoso
bumsfeld is offline Offline
1,422 posts
since Jul 2005
Jan 9th, 2006
1

Re: Why a Set?

Quote originally posted by 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?
you can use the list method somelist.count(x),
which returns the number of i's for which somelist[i] == x :
Python Syntax (Toggle Plain Text)
  1. l=list('a list of characterstrings')
  2. for item in set(l):
  3. print item,'counted',l.count(item),'times'
gives
Python Syntax (Toggle Plain Text)
  1. a counted 3 times
  2. counted 3 times
  3. c counted 2 times
  4. e counted 1 times
  5. ...
Reputation Points: 11
Solved Threads: 2
Newbie Poster
monkeyy is offline Offline
2 posts
since Jan 2006
Jan 9th, 2006
0

Re: Why a Set?

Thanks from the rest of us monkeyy! Great code!
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Feb 10th, 2006
0

Re: Why a Set?

Yes, thanks monkeyy!
Reputation Points: 404
Solved Threads: 180
Nearly a Posting Virtuoso
bumsfeld is offline Offline
1,422 posts
since Jul 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: vba to python
Next Thread in Python Forum Timeline: File Dialog window, save dialog window





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC