Skip to content
Snippets Groups Projects
Commit 982fc6f6 authored by leufen1's avatar leufen1
Browse files

helper to list can now transform sets to lists in addition

parent 7ce6cc81
Branches
Tags
3 merge requests!226Develop,!225Resolve "release v1.2.0",!198Resolve "REFAC: "bad" stations do not report which variable is missing"
This commit is part of merge request !225. Comments created here will be created in the context of that merge request.
...@@ -12,13 +12,15 @@ from typing import Dict, Callable, Union, List, Any ...@@ -12,13 +12,15 @@ from typing import Dict, Callable, Union, List, Any
def to_list(obj: Any) -> List: def to_list(obj: Any) -> List:
""" """
Transform given object to list if obj is not already a list. Transform given object to list if obj is not already a list. Sets are also transformed to a list.
:param obj: object to transform to list :param obj: object to transform to list
:return: list containing obj, or obj itself (if obj was already a list) :return: list containing obj, or obj itself (if obj was already a list)
""" """
if not isinstance(obj, list): if isinstance(obj, set):
obj = list(obj)
elif not isinstance(obj, list):
obj = [obj] obj = [obj]
return obj return obj
...@@ -99,7 +101,7 @@ def remove_items(obj: Union[List, Dict], items: Any): ...@@ -99,7 +101,7 @@ def remove_items(obj: Union[List, Dict], items: Any):
raise TypeError(f"{inspect.stack()[0][3]} does not support type {type(obj)}.") raise TypeError(f"{inspect.stack()[0][3]} does not support type {type(obj)}.")
def select_from_dict(dict_obj: dict, sel_list: str): def select_from_dict(dict_obj: dict, sel_list: Any):
""" """
Extract all key values pairs whose key is contained in the sel_list. Extract all key values pairs whose key is contained in the sel_list.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment