[Python-Dev] function for counting items in a sequence (original) (raw)
Steven Bethard steven.bethard at gmail.com
Sun Apr 8 20:11:06 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 ]
A summary response to the issues raised so far...
On what the name should be:
- Adam Olsen - countunique(), countdistinct(), countduplicates()
- Greg Ewing - counteach(), countall()
- Kevin Jacobs - tally()
- Guido - counts() is fine So I guess I'll stick with counts().
On whether the count of a missing item should be 0 or a KeyError:
- Brett Cannon - 0
- Greg Ewing - 0 Because the number of times an unseen item was seen is 0. So I'll stick with returning 0. That's the normal behavior for a defaultdict(int).
Raymond Hettinger suggested that the function should be called dict.fromcount() instead. I lean towards the collections module instead of a dict classmethod because the feedback above suggests that the count of an unseen item should be 0. This means returning a defaultdict(int), which might be a bit confusing from a classmethod of dict.
Steve
I'm not in-sane. Indeed, I am so far out of sane that you appear a tiny blip on the distant coast of sanity. --- Bucky Katt, Get Fuzzy
- 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 ]