Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update recursive get #188

Open
frehburg opened this issue Oct 17, 2024 · 1 comment
Open

update recursive get #188

frehburg opened this issue Oct 17, 2024 · 1 comment

Comments

@frehburg
Copy link
Member

def recursive_dict_call(d: Dict, keys: List, default=None):
    def index_get(key):
        if '[' in key:
            key = key.split('[')[0]
            id_ = int(key.split('[')[1].split(']')[0])
            return d.get(key, default)[id_]
        return d.get(key, default)

    if not isinstance(d, dict):
        return d
    elif len(keys) == 1:
        return index_get(keys[0])
    else:
        return recursive_dict_call(index_get(keys[0]), keys[1:])
@frehburg
Copy link
Member Author

def recursive_dict_call(d: Dict, keys: List, default=None):
    print(keys[0], '[' in keys[0], keys)

    def index_get(key):
        if '[' in key:
            key = key.split('[')[0]
            id_ = int(key.split('[')[1].split(']')[0])
            return d.get(key, default)[id_]
        return d.get(key, default)

    if not isinstance(d, dict):
        return d
    elif len(keys) == 1:
        return index_get(keys[0])
    else:
        return recursive_dict_call(index_get(keys[0]), keys[1:])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

1 participant