Skip to content

Commit

Permalink
added separate_options
Browse files Browse the repository at this point in the history
  • Loading branch information
István Bozsó committed Feb 14, 2020
1 parent 50633c6 commit d8f656c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
__all__ = (
"Seq", "flat", "new_type", "str_t", "isiter", "all_same",
"make_object", "cat", "compose", "fs", "load", "Enum", "namespace",
"export", "JSONSave"
"export", "JSONSave", "separate_options",
)

py3 = sys.version_info[0] == 3
Expand Down Expand Up @@ -366,4 +366,18 @@ def load_tree(cls, readable, *args, **kwargs):

return namespace(**dd)


def separate_options(d, key, tpl = "%s_"):
txt = tpl % key

keys = tuple(filter(lambda k: k.startswith(txt), d.keys()))

r = {}

for key in keys:
r[key.lstrip(txt)] = d[key]

for key in keys:
del d[key]

return r

0 comments on commit d8f656c

Please sign in to comment.