Created
February 21, 2023 20:27
-
-
Save pmbaumgartner/955aa8100c37e3cbb4bbd9649954b0cd to your computer and use it in GitHub Desktop.
create a dictionary based off of string variable names. based on rust struct shorthand init.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def ndict(*args): | |
"""Return a dictionary with the given keys and their values from globals.""" | |
g = globals() | |
result = {} | |
for arg in args: | |
if arg in g: | |
result[arg] = g[arg] | |
else: | |
raise KeyError(f"Key '{arg}' not found in globals") | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment