[Python-ideas] Adding "Typed" collections/iterators to Python

alex23 wuwei23 at gmail.com
Mon Dec 19 04:39:19 CET 2011

On Dec 19, 12:24 pm, Nathan Rice <nathan.alexander.r... at gmail.com>
> 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. :)

More information about the Python-ideas mailing list