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
>
> def countDups(duplicateList):
> uniqueSet = Set(item for item in duplicateList)
> return[(item, duplicateList.count(item)) for item in uniqueSet]
>
>
>
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-cas
"Becky Mcquilling" wrote
from sets import Set
def countDups(duplicateList):
uniqueSet = Set(item for item in duplicateList)
return[(item, duplicateList.count(item)) for item in uniqueSet]
Can be abbreviated to:
def countDups(duplicateList):
return [(item, duplicateList.count(item)) fo
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']
pr