mirror of https://github.com/python/cpython
Add more detail to the Counter.fromkeys() comment block (GH-8124)
This commit is contained in:
parent
3ae2e33a61
commit
0c4d20bcaa
|
@ -609,8 +609,13 @@ class Counter(dict):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def fromkeys(cls, iterable, v=None):
|
def fromkeys(cls, iterable, v=None):
|
||||||
# There is no equivalent method for counters because setting v=1
|
# There is no equivalent method for counters because the semantics
|
||||||
# means that no element can have a count greater than one.
|
# 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(
|
raise NotImplementedError(
|
||||||
'Counter.fromkeys() is undefined. Use Counter(iterable) instead.')
|
'Counter.fromkeys() is undefined. Use Counter(iterable) instead.')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue