<br><br><div><span class="gmail_quote">On 4/7/07, <b class="gmail_sendername">Steven Bethard</b> <<a href="mailto:steven.bethard@gmail.com">steven.bethard@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On 4/7/07, Steven Bethard <<a href="mailto:steven.bethard@gmail.com">steven.bethard@gmail.com</a>> wrote:<br>> Here's a patch implementing collections.counts() as suggested above:<br>><br>> <a href="http://bugs.python.org/1696199">
http://bugs.python.org/1696199</a><br>><br>> Example usage, from the docstring::<br>><br>> >>> items = 'acabbacba'<br>> >>> item_counts = counts(items)<br>> >>> for item in 'abcd':
<br>> ... print item, item_counts[item]<br>> ...<br>> a 4<br>> b 3<br>> c 2<br>> d 0<br><br>Guido commented in the tracker that it would be worth discussing<br>whether that last item (``item_counts['d']``) should return 0 (as a
<br>defaultdict would) or raise KeyError (as a dict would).<br><br>Anyone have a good motivation for one approach or the other?</blockquote><div><br><br>I say 0 if it is really meant to represent a count as the absense of something is 0. The object returned is being viewed as an object representing the count of items, not specifically as a dict.
<br><br>-Brett</div></div>