Skip to content
Advertisement

Python – How to call every function in a list with a single function call

I’m trying to create a dictionary where each value is a list of functions that should get executed when calling the value. Here’s some pseudo-code:

JavaScript

But if I try to call this using functions["A"]() an exception is thrown saying “TypeError: ‘generator’ object is not callable”.

How should I approach this problem?

EDIT: Just to clarify, the functions are not generators nor have any return type. They just execute some actions based on the parameter.

Advertisement

Answer

ACCEPTED ANSWER:

Thanks to all of your suggestions, I came up with a solution. I’m just going to leave the code here:

JavaScript

This works really well, so thank you all for your help.

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