[Tutor] Equivalent of Set in PtO

Becky Mcquilling ladymcse2000 at gmail.com
Tue Apr 26 09:14:24 CEST 2011


I have a code snippet that I have used to count the duplicates in a list as
such:

from sets import Set

def countDups(duplicateList):
  uniqueSet = Set(item for item in duplicateList)
  return[(item, duplicateList.count(item)) for item in uniqueSet]


lst = ['word', 'word', 'new', 'new', 'new']
print countDups(lst)

The result is: [('new', 3), ('word', 2)], which is what is expected.  This
was using python version 2.7.  I want to do the same thing in Python 3.1,
but I'm not sure what has replaced Set in the newer version, can someone
give me an idea here?

Becky
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110426/a46a95da/attachment-0001.html>


More information about the Tutor mailing list