f=lambdalambda p,q:all(o:=[p.replace("?",a)<q.replace("?",b)for a,b in["AZ","ZA"]])+[p==q,2][any(o)]
Attempt This Online!Attempt This Online!
Anonymous lambda. Returns 3 for left, 0 for right, 2 for undecidable, 1 for equal.
f=lambdalambda p,q: # f(): Given two words, construct an integer... all( # - adding 1 if all the following inequalities hold: o:= # (inequalities, stored as "o": [p.replace("?",a) # left word with its "?"s filled is <q.replace("?",b) # less than right word with its "?"s filled, for a,b in["AZ","ZA"]]) # the fillings being A and Z first, # then Z and A) +[ # - then adding either p==q, # (A) one1 point (conditional on leftwords ==being rightequal) 2 # (B) two2 (unconditional) points ][any(o)] # - with the criterion that (A) is chosen iff # none of the "o" inequalities held. # - left wins = 3 = 1 (all ineqs hold) + 2 (some ineqs hold) # - right wins = 0 = 0 (not all ineqs hold) + 0 (words differ and no ineq holds) # - undecided = 2 = 0 (not all ineqs hold) + 2 (some ineqs hold) # - equal = 1 = 0 (not all ineqs hold) + 1 (words equal and no ineq holds)