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

Add new resolvers oc.dict.keys and oc.dict.values #643

Closed
odelalleau opened this issue Mar 24, 2021 · 0 comments · Fixed by #644
Closed

Add new resolvers oc.dict.keys and oc.dict.values #643

odelalleau opened this issue Mar 24, 2021 · 0 comments · Fixed by #644
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@odelalleau
Copy link
Collaborator

Description

Some config options that are stored as a DictConfig may sometimes be easier to manipulate as lists, when we care only about the keys or the associated values.

Adding new resolvers oc.dict.keys and oc.dict.values will make it easy to access either keys or values as a list:

cfg = OmegaConf.create("""
machines:
  node007: 192.168.0.27
  node012: 192.168.0.35
  node075: 192.168.1.89
nodes: ${oc.dict.keys:${machines}}
ips: ${oc.dict.values:${machines}}  
""")

print(f"cfg.nodes: {cfg.nodes}")  # cfg.nodes: ['node007', 'node012', 'node075']
print(f"cfg.ips: {cfg.ips}")      # cfg.ips  : ['192.168.0.27', '192.168.0.35', '192.168.1.89']

Additional context
See related discussion in #578 (comment)

@odelalleau odelalleau self-assigned this Mar 24, 2021
@odelalleau odelalleau added this to the OmegaConf 2.1 milestone Mar 24, 2021
odelalleau added a commit to odelalleau/omegaconf that referenced this issue Mar 24, 2021
@omry omry added the enhancement New feature or request label Mar 27, 2021
odelalleau added a commit to odelalleau/omegaconf that referenced this issue Mar 30, 2021
odelalleau added a commit to odelalleau/omegaconf that referenced this issue Apr 7, 2021
odelalleau added a commit to odelalleau/omegaconf that referenced this issue Apr 10, 2021
odelalleau added a commit to odelalleau/omegaconf that referenced this issue Apr 10, 2021
odelalleau added a commit to odelalleau/omegaconf that referenced this issue Apr 10, 2021
@omry omry closed this as completed in #644 Apr 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants