[Python-ideas] Add an identity function

dag.odenhall at gmail.com dag.odenhall at gmail.com
Sun Aug 7 01:50:09 CEST 2011

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.


More information about the Python-ideas mailing list