absfuyu.dxt.dictext module

Absfuyu: Data Extension

dict extension

Version: 5.1.0 Date updated: 10/03/2025 (dd/mm/yyyy)

class absfuyu.dxt.dictext.DictExt[source]

Bases: ShowAllMethodsMixin, dict

dict extension

analyze() DictAnalyzeResult[source]

Analyze all the key values (int, float) in dict then return highest/lowest index

Returns:

Analyzed data

Return type:

dict

Example:

>>> test = DictExt({
...     "abc": 9,
...     "def": 9,
...     "ghi": 8,
...     "jkl": 1,
...     "mno": 1
... })
>>> test.analyze()
DictAnalyzeResult(max_value=9, min_value=1, max_list=[('abc', 9), ('def', 9)], min_list=[('jkl', 1), ('mno', 1)])

Changed in version 3.3.0: Updated return type

swap_items() Self[source]

Swap dict.keys() with dict.values()

Returns:

Swapped dict

Return type:

DictExt

Example:

>>> test = DictExt({"abc": 9})
>>> test.swap_items()
{9: 'abc'}
apply(func: Callable, apply_to_value: bool = True) Self[source]

Apply function to DictExt.keys() or DictExt.values()

Parameters:
  • func (Callable) – Callable function

  • apply_to_value (bool) –

    True: Apply func to DictExt.values()
    False: Apply func to DictExt.keys()

Returns:

DictExt

Return type:

DictExt

Example:

>>> test = DictExt({"abc": 9})
>>> test.apply(str)
{'abc': '9'}
aggregate(other_dict: dict, default_value: ~typing.Any = 0, operator_func: ~collections.abc.Callable[[~typing.Any, ~typing.Any], ~typing.Any] = <built-in function add>) Self[source]

Aggregates the values of the current dictionary with another dictionary.

For each unique key, this method applies the specified operator to the values from both dictionaries. If a key exists in only one dictionary, its value is used. If an error occurs during aggregation (e.g., incompatible types), the values from both dictionaries are returned as a list.

Parameters:
  • other_dict (dict) – The dictionary to aggregate with.

  • default_value (Any, optional) – The value to use for missing keys, by default 0

operator_funcCallable[[Any, Any], Any], optional

A function that takes two arguments and returns a single value, by default operator.add

Returns:

A new instance of the aggregated dictionary.

Return type:

Self

Example:

>>> test = DictExt({"test": 5, "test2": 9})
>>> agg = {"test1": 10, "test2": 1}
>>> print(test.aggregate(agg))
{'test1': 10, 'test': 5, 'test2': 10}
>>> test = DictExt({"test": 5, "test2": 9})
>>> agg = {"test1": 10, "test2": "1"}
>>> print(test.aggregate(agg))
{'test1': 10, 'test': 5, 'test2': [9, '1']}

Added in version 3.4.0

Changed in version 5.0.0: Updated to handle more types and operator

class absfuyu.dxt.dictext.DictAnalyzeResult(max_value: int | float, min_value: int | float, max_list: list, min_list: list)[source]

Bases: NamedTuple

Result for DictExt.analyze()

max_value: int | float

Alias for field number 0

min_value: int | float

Alias for field number 1

max_list: list

Alias for field number 2

min_list: list

Alias for field number 3