Producing a List / Dictionary of Variables in a Python Program

There are two tools that allow you to return a dictionary of the the variable and variable value.
locals() - Returns the variables that are in the local name space of where this is executed.
globals() - Returns the variables that are in the global name space of the program.

Example - Locals()

x = 5
f = 56

def something(x):
    x = 4
    f = 5
    i = 5
    print (locals())

something (x)
Returns:
{'i': 5, 'x': 4, 'f': 5}
If we call the locals() after running this.
x = 5
f = 56

def something(x):
    x = 4
    f = 5
    i = 5
    print (locals())

something (x)
print (locals())
Returns:
{'i': 5, 'x': 4, 'f': 5}
{'__spec__': None, 'something': <function something at 0x03163270>, '__doc__': None, '__loader__': <class '_frozen_importlib.BuiltinImporter'>, '__builtins__': <module 'builtins' (built-in)>, '__name__': '__main__', 'x': 5, 'f': 56, '__package__': None, '__file__': 'C:/globals-locals.py'}

Example - Globals()

x = 5
f = 56

def something(x):
    x = 4
    f = 5
    i = 5
    print (globals())

something (x)
print (globals())
Returns:

{'__doc__': None, 'f': 56, '__file__': 'C:/globals-locals.py', 'x': 5, '__builtins__': <module built-in="" builtins="">, '__spec__': None, '__name__': '__main__', '__package__': None, 'something': <function 0x031a2270="" at="" something="">, '__loader__': <class frozen_importlib.builtinimporter="">}
{'__doc__': None, 'f': 56, '__file__': 'C:/globals-locals.py', 'x': 5, '__builtins__': <module built-in="" builtins="">, '__spec__': None, '__name__': '__main__', '__package__': None, 'something': <function 0x031a2270="" at="" something="">, '__loader__': <class frozen_importlib.builtinimporter="">}