assert flatten_list([[1], [2]]) == [1, 2]
Utils
Python helper functions
flatten_list
flatten_list (input:list[list])
Flattens list of lists (not recursive)
Type | Details | |
---|---|---|
input | list | nested list |
Returns | list | flattened list |
deduplicate_list
deduplicate_list (input:list, key_func:Optional[Callable]=None)
deduplicates list while maintaining order
Type | Default | Details | |
---|---|---|---|
input | list | input list containing duplicates | |
key_func | typing.Optional[typing.Callable] | None | function to generate deduplication keys |
Returns | list | output list, deduplicated |
assert deduplicate_list([1,2,2,3,5,3]) == [1, 2, 3, 5]
assert deduplicate_list(['C', 'CC', 'CN'], key_func=lambda x: len(x)) == ['C', 'CN']
validate_range
validate_range (min_val:Union[int,float,NoneType], max_val:Union[int,float,NoneType], min_limit:Union[int,float], max_limit:Union[int,float])
given a range min_val
, max_val
, and range limits min_limit
, max_limit
, this function verifies that min_limit < min_val < max_val < max_limit
and returns the resolved range
Type | Details | |
---|---|---|
min_val | typing.Union[int, float, NoneType] | minimum range value |
max_val | typing.Union[int, float, NoneType] | maximum range value |
min_limit | typing.Union[int, float] | min value limit - replaces min_val if min_val is None |
max_limit | typing.Union[int, float] | max value limit - replaces max_val if max_val is None |
Returns | typing.Tuple[typing.Union[int, float], typing.Union[int, float]] | resolved [min_val, max_val] range |