There is a way to do it (in Python 3) without using a lambda: functools.singledispatch. With this, you can create a single-dispatch generic function:
A form of generic function dispatch where the implementation is chosen
based on the type of a single argument.
[Emphasis mine]
It adds overloaded implementations to the function which are called depending on the type of the first argument, and fortunately, your p12 function takes only one argument.
from functools import singledispatch
@singledispatch
def p12(p):
...
@p12.register(int)
def _(p):
'''compare integers'''
...
@p12.register(str)
def _(p):
'''compare strings'''
...
p12(0) # calls integer dispatch
p12('') # calls string dispatch
And you can still add more candidate functions for other Python types to overload p12.
lambdashouldn't be used if you are going to name it anyway... it defeats the entire purpose of an anonymous function.lambda.