Skip to content
Advertisement

How can i make this Python code less repetitive?

I was looking for the way to call different functions based on variable and i came up with this dictionary mapping. I wonder if there is a way to somehow improve it and make it less repetitive?

JavaScript

Advertisement

Answer

You can use getattr to get the property name from a string:

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