Skip to content

Instantly share code, notes, and snippets.

@tdowgielewicz
Created September 6, 2019 09:43
Show Gist options
  • Save tdowgielewicz/2c81fbd83896044939447b5fdf037c4b to your computer and use it in GitHub Desktop.
Save tdowgielewicz/2c81fbd83896044939447b5fdf037c4b to your computer and use it in GitHub Desktop.
def autodict(*args):
"""
Creates dictonary from python variables where key is variable name and value is var value
:param args: python variables
:return: dictonary
"""
g = {k: v for k, v in globals().items() if not k.startswith('__')}
result = {}
for arg in args:
for k, v in g.items():
try:
if v == arg:
result[k] = v
except ValueError:
continue
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment