From 313128f0951ab36cfbcc01a20178673a7e315031 Mon Sep 17 00:00:00 2001 From: Scott Gasch Date: Sun, 11 Jun 2023 09:11:48 -0700 Subject: [PATCH] Just update pydocs. --- src/pyutils/dict_utils.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/pyutils/dict_utils.py b/src/pyutils/dict_utils.py index a675213..0dbe18a 100644 --- a/src/pyutils/dict_utils.py +++ b/src/pyutils/dict_utils.py @@ -21,14 +21,17 @@ def init_or_inc( init_value: Any = 1, inc_function: Callable[..., Any] = lambda x: x + 1, ) -> bool: - """ - Initialize a dict value (if it doesn't exist) or increments it (using the + """Initialize a dict value (if it doesn't exist) or increments it (using the inc_function, which is customizable) if it already does exist. + See also :py:class:`defaultdict` + (https://docs.python.org/3/library/collections.html#collections.defaultdict) + for a more pythonic alternative. + Args: d: the dict to increment or initialize a value in key: the key to increment or initialize - init_value: default initial value + init_value: default initial value (see also :meth:`dict.setdefault`) inc_function: Callable use to increment a value Returns: @@ -46,6 +49,7 @@ def init_or_inc( False >>> d {'test': 2, 'ing': 1} + """ if key in d.keys(): d[key] = inc_function(d[key]) -- 2.47.1