This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: defaultdict example in py3 doc should mention the new Counter class
Type: Stage:
Components: Documentation Versions: Python 3.1, Python 3.2
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, ezio.melotti, georg.brandl, rhettinger
Priority: low Keywords:

Created on 2009-09-12 03:03 by ezio.melotti, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg92534 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2009-09-12 03:03
The 3rd example of defaultdict [1] shows how to use it to count the
letters of a string, but the new Counter class is a better tool for
doing that.

Possible solutions:
1) "Setting the default_factory to int makes the defaultdict useful for
counting (like a bag or multiset in other languages):" -> "Setting the
default_factory to int makes the defaultdict useful for basic counting
(see also the Counter class for more features):";
2) remove the example.

[1]:
http://docs.python.org/dev/py3k/library/collections.html#defaultdict-examples
msg116597 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2010-09-16 19:25
This example needs to stay.  It was one of the principal motiviating use cases for defaultdict and it is a good, simple, understandable example of how to use it.

Also, I don't want to cross-link these two tools because they a subtly different (the default dict approach inserts a zero for missing elements while the Counter approach returns zero but does not insert it).
History
Date User Action Args
2022-04-11 14:56:52adminsetgithub: 51142
2010-09-16 19:25:52rhettingersetstatus: open -> closed
resolution: rejected
messages: + msg116597
2010-09-16 16:37:18BreamoreBoysetassignee: georg.brandl -> docs@python

nosy: + docs@python
2009-09-12 03:03:42ezio.melotticreate