diff options
author | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2018-07-05 23:36:24 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-05 23:36:24 (GMT) |
commit | 0c4d20bcaa538d029c24b1163e1e822f2d887371 (patch) | |
tree | 96592120fd83113e404b24c4980fe4ed397b24ff /Lib/collections | |
parent | 3ae2e33a61f8aebbe6ce16f1030687a6e66dbb72 (diff) | |
download | cpython-0c4d20bcaa538d029c24b1163e1e822f2d887371.zip cpython-0c4d20bcaa538d029c24b1163e1e822f2d887371.tar.gz cpython-0c4d20bcaa538d029c24b1163e1e822f2d887371.tar.bz2 |
Add more detail to the Counter.fromkeys() comment block (GH-8124)
Diffstat (limited to 'Lib/collections')
-rw-r--r-- | Lib/collections/__init__.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index 3109054..cd2d2bf 100644 --- a/Lib/collections/__init__.py +++ b/Lib/collections/__init__.py @@ -609,8 +609,13 @@ class Counter(dict): @classmethod def fromkeys(cls, iterable, v=None): - # There is no equivalent method for counters because setting v=1 - # means that no element can have a count greater than one. + # There is no equivalent method for counters because the semantics + # would be ambiguous in cases such as Counter('aaabbc', v=2). + # Initializing counters to zero values isn't necessary because zero + # is already the default value for counter lookups. Initializing + # to one is easily accomplished with Counter(set(iterable)). For + # more exotic cases, create a dictionary first using a dictionary + # comprehension or dict.fromkeys(). raise NotImplementedError( 'Counter.fromkeys() is undefined. Use Counter(iterable) instead.') |