<[EMAIL PROTECTED]> wrote: > Alex> I've seen enough occurrences of "lambda x: x" in Python code with > Alex> a generally functional style that I'd love to have > Alex> operator.identity (and a few more trivial functions like that) for > Alex> readability;-) > > But, but, but [Skip gets momentarily apoplectic, then recovers...] > "operator.identity" is way more to type than "lambda x: x". Plus you have > to remember to import the operator module. <0.5 wink>
But, it's way more readable, IMHO. > Not to mention which (from "pydoc operator"): > > [The operator module] exports a set of functions implemented in C > corresponding to the intrinsic operators of Python. > > Last time I checked, Python didn't have an intrinsic "identity" operator. attrgetter and itemgetter don't exactly correspond to "intrinsic operators", either (getitem, and the built-in getattr, are more like that)... yet module operator exports them today, offering more readable (and faster) alternatives to "lambda x: x[y]" and "lambda x: getattr(x, y)". > For which reason, I'd be -1 on the idea of an identity function, certainly > in the operator module. I'm not at all wedded to having 'identity' in the operator module (which may arguably be the wrong placement for 'attrgetter' and 'itemgetter' too). But identity is a useful primitive for a functional style of Python programming, so having it SOMEwhere would be nice, IMHO. Alex -- http://mail.python.org/mailman/listinfo/python-list