Is there any built-in stub function that returns the same object it was given? I'm looking for a shortcut to lambda x: x
(like operator.itemgetter(1)
is a shortcut and more efficient way of saying lambda x: x[1]
).
I technically wish for the boolean value, but timeit
showed that lambda x: x
was faster than bool()
(probably because bool
creates a new object) by 10%, and since it's being defined a few times but called many more, it makes a difference.
I only use the variable for if
statements so I don't care whether it returns True
or the value itself and tested using __bool__
.