[Python-ideas] Add an identity function
jxo6948 at rit.edu
Sun Aug 7 02:50:03 CEST 2011
Personally I find lambda x: x to be very readable. It seems quite close to
f(x) = x
On Sat, Aug 6, 2011 at 4:50 PM, dag.odenhall at gmail.com <
dag.odenhall at gmail.com> wrote:
> Yes, I know, it's merely a (lambda x: x), but I find a need for this
> often enough that dedicated, documented function would help
> readability and encourage certain patterns. Whether it should go in
> builtins or functools is debatable. A name that is neither in conflict
> or easily confused with the id() builtin is another problem (the
> Haskell identity function is called 'id').
> So what is the use case? A common example is the pattern of "key
> functions" as used with sorting: the default is typically the
> "identity function". Another example is gettext catalogs, which
> effectively are defaultdicts of the identity function.
> Python-ideas mailing list
> Python-ideas at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas