Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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.
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.
map
for
Add a comment
You could use functools.partial to provide arguments to a function before calling it:
functools.partial
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!
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.