ahvn.utils.basic.misc_utils module¶
- ahvn.utils.basic.misc_utils.unique(iterable, key=lambda x: ...)[源代码]¶
Return a list of unique elements from an iterable, preserving order.
- 参数:
- 返回:
A list containing only the unique elements from the input iterable.
- 返回类型:
List[Any]
示例
>>> unique([1, 2, 2, 3, 1]) [1, 2, 3] >>> unique(['apple', 'banana', 'orange'], key=len) ['apple', 'banana']
- ahvn.utils.basic.misc_utils.lflat(iterable)[源代码]¶
Flatten a nested iterable (2 levels deep) into a single list.
- 参数:
iterable (Iterable[Iterable[Any]]) -- The nested iterable to flatten.
- 返回:
A flat list containing all elements from the nested iterable.
- 返回类型:
List[Any]
示例
>>> lflat([[1, 2], [3, 4]]) [1, 2, 3, 4]
- ahvn.utils.basic.misc_utils.counter_percentiles(counter, percentiles={0, 25, 50, 75, 100})[源代码]¶
Calculate specified percentiles from a frequency counter.
- 参数:
- 返回:
A dictionary mapping each requested percentile to its corresponding value.
- 返回类型:
示例
>>> counter = {1: 2, 2: 3, 3: 5} >>> counter_percentiles(counter, [0, 50, 100]) {0: 1, 50: 2, 100: 3}