[ python-Bugs-1696199 ] Add collections.counts()
SourceForge.net
noreply at sourceforge.net
Sun Apr 8 01:39:25 CEST 2007
Bugs item #1696199, was opened at 2007-04-07 17:38
Message generated for change (Comment added) made by gvanrossum
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1696199&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.6
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Steven Bethard (bediviere)
Assigned to: Nobody/Anonymous (nobody)
Summary: Add collections.counts()
Initial Comment:
As suggested in http://mail.python.org/pipermail/python-list/2007-April/433986.html this is a patch to add a counts() function to the collections module. Usage looks like:
>>> items = 'acabbacba'
>>> item_counts = counts(items)
>>> for item in 'abcd':
... print item, item_counts[item]
...
a 4
b 3
c 2
d 0
Yes, it's only a 4-line function, but it's a frequently re-written 4-line function.
----------------------------------------------------------------------
>Comment By: Guido van Rossum (gvanrossum)
Date: 2007-04-07 19:39
Message:
Logged In: YES
user_id=6380
Originator: NO
Does it have to be a defaultdict? I.e. is it important that
item_counts['d'] not raise KeyError?
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1696199&group_id=5470
More information about the Python-bugs-list
mailing list