speasy.core.algorithms module

class speasy.core.algorithms.AllowedKwargs(allowed_list)[source]

Bases: object

A decorator that prevent from passing unexpected kwargs to a function

speasy.core.algorithms.fix_name(name: str)[source]

Makes given input compatible with python charset https://docs.python.org/3/reference/lexical_analysis.html#identifiers

Parameters:
name: str

input string to sanitize

Returns:
str

a string compatible with python naming rules

Examples

>>> fix_name('Parker Solar Probe (PSP)')
'Parker_Solar_Probe_PSP'
>>> fix_name('IS⊙ISEPI_Lo')
'ISoISEPI_Lo'
>>> fix_name('all_Legal_strings_123')
'all_Legal_strings_123'
speasy.core.algorithms.pack_kwargs(**kwargs: Any) Dict[source]

Packs given keyword arguments into a dictionary

Parameters:
kwargs: Any

Any keyword argument is accepted

Returns:
dict

A dict with all kwargs packed

Examples

>>> pack_kwargs(a=1, b="2")
{'a': 1, 'b': '2'}
speasy.core.algorithms.randomized_map(f: Callable, l, *args, **kwargs)[source]

Applies function f to all elements in list l in a randomized order

Parameters:
f: Callable

function to apply to each element in l

l: list

list of elements to process

args: Any

additional positional arguments to pass to f

kwargs: Any

additional keyword arguments to pass to f

Returns:
list

A list with the results of applying f to each element in l, in the original order

Examples

>>> randomized_map(lambda x: x**2, [1,2,3,4])
[1, 4, 9, 16]