Why a Set?

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jul 2005
Posts: 1,221
Reputation: bumsfeld will become famous soon enough bumsfeld will become famous soon enough 
Solved Threads: 138
bumsfeld's Avatar
bumsfeld bumsfeld is offline Offline
Nearly a Posting Virtuoso

Why a Set?

 
0
  #1
Nov 20th, 2005
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?
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 133
Reputation: mawe is an unknown quantity at this point 
Solved Threads: 58
mawe mawe is offline Offline
Junior Poster

Re: Why a Set?

 
1
  #2
Nov 20th, 2005
Hi!

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

Regards, mawe
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,221
Reputation: bumsfeld will become famous soon enough bumsfeld will become famous soon enough 
Solved Threads: 138
bumsfeld's Avatar
bumsfeld bumsfeld is offline Offline
Nearly a Posting Virtuoso

Re: Why a Set?

 
0
  #3
Nov 20th, 2005
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?
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 2
Reputation: monkeyy is an unknown quantity at this point 
Solved Threads: 2
monkeyy monkeyy is offline Offline
Newbie Poster

Re: Why a Set?

 
1
  #4
Jan 9th, 2006
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 :
  1. l=list('a list of characterstrings')
  2. for item in set(l):
  3. print item,'counted',l.count(item),'times'
gives
  1. a counted 3 times
  2. counted 3 times
  3. c counted 2 times
  4. e counted 1 times
  5. ...
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,109
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 943
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Why a Set?

 
0
  #5
Jan 9th, 2006
Thanks from the rest of us monkeyy! Great code!
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,221
Reputation: bumsfeld will become famous soon enough bumsfeld will become famous soon enough 
Solved Threads: 138
bumsfeld's Avatar
bumsfeld bumsfeld is offline Offline
Nearly a Posting Virtuoso

Re: Why a Set?

 
0
  #6
Feb 10th, 2006
Yes, thanks monkeyy!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC