Explain the LEGB (Local, Enclosing, Global, Built-in) rule in Python with a clear example.
Implement demonstrate_legb(items) to return a dictionary showing one value resolved from each LEGB scope. Use a nested function, a module-level variable, and the built-in len function.
The function accepts a list and returns a dictionary with keys local, enclosing, global, and built_in.
items is a list.local, enclosing, global, and built_in.local, enclosing, and global must identify their corresponding scopes.def demonstrate_legb(items):