[Python-Dev] function for counting items in a sequence (original) (raw)
Adam Olsen rhamph at gmail.com
Sun Apr 8 03:04:08 CEST 2007
- Previous message: [Python-Dev] function for counting items in a sequence
- Next message: [Python-Dev] function for counting items in a sequence
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 4/7/07, Steven Bethard <steven.bethard at gmail.com> wrote:
Here's a patch implementing collections.counts() as suggested above:
The name doesn't make it obvious to me what's going on. Maybe countunique()? Some other options are countdistinct() and countduplicates().
>>> items = 'acabbacba' >>> itemcounts = counts(items) >>> for item in 'abcd': ... print item, itemcounts[item] ... a 4 b 3 c 2 d 0
Would become:
items = 'acabbacba' counts = countunique(items) for item in 'abcd': ... print item, counts[item] ... a 4 b 3 c 2 d 0
-- Adam Olsen, aka Rhamphoryncus
- Previous message: [Python-Dev] function for counting items in a sequence
- Next message: [Python-Dev] function for counting items in a sequence
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]