Skip to content

Commit

Permalink
Added dict functions
Browse files Browse the repository at this point in the history
  • Loading branch information
awicenec committed Mar 22, 2024
1 parent 63b1605 commit 593bb72
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions daliuge-engine/dlg/apps/simple_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,36 @@ def string2json(string: str, pickle_flag: bool = False) -> list:
return json.loads(string)
else:
return pickle.dumps(json.loads(string))


def value_from_dict(dict_in: dict, dict_key: str) -> Any:
"""
Select a value from a dictionary.
Parameters:
-----------
dict_in: input dictionary
dict_key: keyword to select
Returns:
--------
The value referred to by key.
"""
# We deliberatly let this fail if the type is not str or array like
dict_key = dict_key if isinstance(dict_key, str) else dict_key[0]
return dict_in[dict_key]


def keys_from_dict(dict_in: dict) -> list:
"""
Return key list of dictionary.
Parameters:
-----------
dict_in: input dictionary
Returns:
--------
The list of keys
"""
return list(dict_in.keys())

0 comments on commit 593bb72

Please sign in to comment.