Skip to content
Advertisement

Using eval within a dict

I want to evaluate the value of a dict key, using the dict itself. For example:

JavaScript

When I do this it includes a bunch of unnecessary stuff in the dict. In the above example it prints:

JavaScript

Instead, in the above example I just want:

JavaScript

How to resolve this issue? Thank you!

Advertisement

Answer

Pass a copy of dict to eval():

JavaScript

Prints:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement