From: Raymond Hettinger Date: Thu, 5 Jul 2018 23:36:24 +0000 (-0700) Subject: Add more detail to the Counter.fromkeys() comment block (GH-8124) X-Git-Tag: v3.8.0a1~1435 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0c4d20bcaa538d029c24b1163e1e822f2d887371;p=thirdparty%2FPython%2Fcpython.git Add more detail to the Counter.fromkeys() comment block (GH-8124) --- diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index 3109054e20c1..cd2d2bfc1073 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.')