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

from sets import Set

Since Python 2.4, you no longer need to import module "sets" (note plural) to get Set (note capital letter). You can just use the built-in name "set" (note lower-case letter).


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

This becomes:

uniqueSet = set(item for item in duplicateList)


Another advantage is that the built-in set is much faster than sets.Set.




--
Steven

_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to