diff options
| author | Scott Gasch <[email protected]> | 2021-09-15 09:32:08 -0700 |
|---|---|---|
| committer | Scott Gasch <[email protected]> | 2021-09-15 09:32:08 -0700 |
| commit | 4c315e387f18010ba0b5661744ad3c792f21d2d1 (patch) | |
| tree | a5657340bea356aa3aaf2c24b7f2be98bb4bc302 /dict_utils.py | |
| parent | 83c1e0d04fe2e78963c8b508e8b7d0ae03bfcb16 (diff) | |
Adding doctests. Also added a logging filter.
Diffstat (limited to 'dict_utils.py')
| -rw-r--r-- | dict_utils.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/dict_utils.py b/dict_utils.py index 6dd79f3..92fd1e0 100644 --- a/dict_utils.py +++ b/dict_utils.py @@ -25,6 +25,7 @@ def init_or_inc( False >>> d {'test': 2, 'ing': 1} + """ if key in d.keys(): d[key] = inc_function(d[key]) @@ -71,6 +72,7 @@ def coalesce( >>> c = {'c': 1, 'd': 2} >>> coalesce([a, b, c]) {'a': 1, 'b': [1, 2], 'c': [1, 2], 'd': [2, 3]} + """ out: Dict[Any, Any] = {} for d in inputs: @@ -93,6 +95,7 @@ def item_with_max_value(d: Dict[Any, Any]) -> Tuple[Any, Any]: Traceback (most recent call last): ... ValueError: max() arg is an empty sequence + """ return max(d.items(), key=lambda _: _[1]) @@ -103,6 +106,7 @@ def item_with_min_value(d: Dict[Any, Any]) -> Tuple[Any, Any]: >>> d = {'a': 1, 'b': 2, 'c': 3} >>> item_with_min_value(d) ('a', 1) + """ return min(d.items(), key=lambda _: _[1]) @@ -113,6 +117,7 @@ def key_with_max_value(d: Dict[Any, Any]) -> Any: >>> d = {'a': 1, 'b': 2, 'c': 3} >>> key_with_max_value(d) 'c' + """ return item_with_max_value(d)[0] @@ -123,6 +128,7 @@ def key_with_min_value(d: Dict[Any, Any]) -> Any: >>> d = {'a': 1, 'b': 2, 'c': 3} >>> key_with_min_value(d) 'a' + """ return item_with_min_value(d)[0] @@ -133,6 +139,7 @@ def max_value(d: Dict[Any, Any]) -> Any: >>> d = {'a': 1, 'b': 2, 'c': 3} >>> max_value(d) 3 + """ return item_with_max_value(d)[1] @@ -143,6 +150,7 @@ def min_value(d: Dict[Any, Any]) -> Any: >>> d = {'a': 1, 'b': 2, 'c': 3} >>> min_value(d) 1 + """ return item_with_min_value(d)[1] @@ -153,6 +161,7 @@ def max_key(d: Dict[Any, Any]) -> Any: >>> d = {'a': 3, 'b': 2, 'c': 1} >>> max_key(d) 'c' + """ return max(d.keys()) @@ -163,6 +172,7 @@ def min_key(d: Dict[Any, Any]) -> Any: >>> d = {'a': 3, 'b': 2, 'c': 1} >>> min_key(d) 'a' + """ return min(d.keys()) |
