19 Dec
2011
19 Dec
'11
9:09 a.m.
On Dec 19, 12:24 pm, Nathan Rice
Yes, but map(lambda x: getattr(x, "method")(), thing) is ugly
from operator import methodcaller method = methodcaller('method') result = map(method, thing)
map(lambda x: x.method_2(param), map(lambda x: x.method(param), thing)) is really ugly.
method = methodcaller('method', param) method2 = methodcaller('method_2', param) result = map(method2, map(method, thing)) If your code is ugly, stop writing ugly code. :)