[Python-bugs-list] [ python-Feature Requests-739029 ] Constructor
for counting things
SourceForge.net
noreply at sourceforge.net
Tue Aug 12 00:12:09 EDT 2003
Feature Requests item #739029, was opened at 2003-05-16 19:22
Message generated for change (Comment added) made by bcannon
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=739029&group_id=5470
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: David Albert Torpey (dtorp)
Assigned to: Nobody/Anonymous (nobody)
Summary: Constructor for counting things
Initial Comment:
Counting things is very common. May I suggest an
alternate dictionary constructor that works like this:
class BetterDictionary(dict):
def bag(classobject, sequence):
"Fast way to count things"
b = classobject()
for k in sequence:
b[k] = b.get(k,0) + 1
return b
bag = classmethod(bag)
print BetterDictionary.bag("jack and jill went up a
hill ...")
A C implementation could do this very fast.
----------------------------------------------------------------------
>Comment By: Brett Cannon (bcannon)
Date: 2003-08-11 23:12
Message:
Logged In: YES
user_id=357491
I don't know if it is *that* common. Besides, as your code shows,
it isn't that complex. It strikes me as a little too specific to be
made a built-in dict constructor.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=739029&group_id=5470
More information about the Python-bugs-list
mailing list