mixle.utils.optsutil module¶
- map_to_integers(x, val_map)[source]
Map sequence of type T to integers.
- get_inv_map(val_map)[source]
Obtain the inverse dictionary mapping of key/value pairs.
- Parameters:
val_map (Dict[T1, T]) – Dictionary mapping keys to values.
- Returns:
Inverse mapping of val_map (value -> key).
- Return type:
dict[T1, T]
- text_file(f)[source]
Open a file and split by newline.
- Args
f: File to be read-in and parsed.
- reduce_by_key(f, x)[source]
Reduce sequence of tuple of key value pairs under grouping function f.
- Parameters:
f (Callable[[T1, T1], T1]) – Function for reducing keys.
x (Sequence[Tuple[T, T1]) – A sequence of key/value pairs.
- Returns:
Dictionary mapping key types T to value types T1.
- Return type:
dict[T, T1]
- sum_by_key(x)[source]
Sum values and return dictionary of items with their respective summed values.
- Parameters:
x (Sequence[Tuple[T, T1]]) – A sequence of tuples of key and value pairs.
- Returns:
Dictionary of keys with summed values.
- Return type:
dict[T, T1]
- group_by_key(x)[source]
Group keys and return dictionary of items with their respective values aggregated as a list.
- group_by(f, x)[source]
Maps values in x to key from mapping f. Dictionary mapping keys to list of grouped values in x is returned.
- count_by_value(x)[source]
Count the number of observations of a given value in arg ‘x’.