Appliying method to list of objects

Daniel Dittmar daniel.dittmar at sap.com
Thu May 31 10:38:05 EDT 2001


> map( lambda x: x.dosomething(), list )

If all the x are from the same class, you could try:
map (SomeClass.dosomething, list)

or :

class Method:
    def __init__ (self, methodName):
        self.name = methodName

    def __call__ (self, arg, *args):
        apply (getattr (arg, self.name), args)

map (Method ('dosomething'), list)

Daniel







More information about the Python-list mailing list