[Python-ideas] Add an identity function
John O'Connor
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
- John
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.
>
> http://en.wikipedia.org/wiki/Identity_function
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110806/31a4b540/attachment.html>
More information about the Python-ideas
mailing list