0

Very simple

I have this:

for i in self.Abilities:
    i.OnTimer(amount)

Can i have something like this instead?

map(Ability.OnTimer,self.Abilities,amount)

I want to use map with class functions but i can't get it to work.

2 Answers 2

6

You should use map to calculate a list of values, not for its side effects. If you're performing a sequence of actions, it's more readable to use the for loop. People will more easily understand the intent of your code.

Sign up to request clarification or add additional context in comments.

Comments

4

You could use functools.partial to provide arguments to a function before calling it:

from functools import partial

map(partial(Ability.OnTimer, amount = amount), self.Abilities)

But do you really think this would be more readable? And mind that map is lazy in Python 3!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.