lambda l:eval("(%sin[%s,%s]or %s)*"*3%(l*4)+"1")
Try it online!
Takes in a tuple. The idea is similar to an answer in the Code Review question, which can be golfed to:
51 bytes
lambda a,b,c:a**(b!=a!=c)*b**(c!=b!=a)*c**(a!=c!=b)
Try it online!
Each element is included in the product if it's different from the other two, with the power setting to a harmless x**0 == 1
otherwise. We want to avoid writing the three similar terms being multiplied. Python unfortunately doesn't have a built-in list product without imports. So, we turn to eval
shenanigans.
We use a longer expression that use logical short-circuiting:
60 bytes
lambda a,b,c:(a in[b,c]or a)*(b in[c,a]or b)*(c in[a,b]or c)
Try it online!
In this expression, the variable names cycle through a,b,c
in that order four times. So, by tripling the format string "(%sin[%s,%s]or %s)*"
and plugging in the input tuple repeated four times, we get the desired expression. We just need to append a "1"
to deal with the trailing multiplication.