Re: [Tutor] Equivalent of Set in PtO

2011-04-26 Thread Peter Otten
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] > > >

Re: [Tutor] Equivalent of Set in PtO

2011-04-26 Thread Steven D'Aprano
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

Re: [Tutor] Equivalent of Set in PtO

2011-04-26 Thread Alan Gauld
"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

[Tutor] Equivalent of Set in PtO

2011-04-26 Thread Becky Mcquilling
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