A nifty dictionary comprehension can be used.
To get all global scoped variables, you can simply do the below:
global_var = {key: globals()[key] for i in args for key in globals().keys() if i == globals()[key]}
To get all the local scoped variables, you can simply to the below:
local_var = {key: locals()[key] for i in args for key in locals().keys() if i == locals()[key]}
If you're using them together, make sure you add them in a single dict
so that you avoid modifying the collection on which you're iterating
If you wana learn more about scopes in python refer to this