Bugs item #1696199, was opened at 2007-04-07 16:38 Message generated for change (Settings changed) made by rhettinger 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: Raymond Hettinger (rhettinger) 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:23 Message: Logged In: YES user_id=6380 Originator: NO I guess it's simplicity of implementation vs. simplicity of use. And I'm not even sure which is easier to use. It's just that defaultdicts are a very new thing and still feel "weird" -- even though I pushed for the implementation based on popular demand I'm not a user myself. Perhaps ask around on python-dev? ---------------------------------------------------------------------- Comment By: Steven Bethard (bediviere) Date: 2007-04-07 18:48 Message: Logged In: YES user_id=945502 Originator: YES I think it's okay if it's not a defaultdict. That was the simplest implementation, but I certainly have no problem calling d.get() when necessary. Should I change the implementation to use a dict()? ---------------------------------------------------------------------- Comment By: Guido van Rossum (gvanrossum) Date: 2007-04-07 18: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 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com